CREATE TABLE sessions (
    id         UUID        PRIMARY KEY DEFAULT gen_uuid_v7(),
    workout    UUID        NOT NULL REFERENCES workouts(id) ON DELETE CASCADE,
    user_id    UUID        NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    start_time TIMESTAMPTZ NOT NULL,
    end_time   TIMESTAMPTZ NOT NULL
);

CREATE TABLE session_exercises (
    id               UUID          PRIMARY KEY DEFAULT gen_uuid_v7(),
    session          UUID          NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
    exercise         UUID          NOT NULL REFERENCES exercises(id) ON DELETE CASCADE,
    name             TEXT          NOT NULL,
    notes            TEXT,
    exercise_type    exercise_type NOT NULL,
    position         INTEGER       NOT NULL
);

CREATE TABLE session_sets (
    id               UUID          PRIMARY KEY DEFAULT gen_uuid_v7(),
    session_exercise UUID          NOT NULL REFERENCES session_exercises(id) ON DELETE CASCADE,
    reps             INTEGER,
    weight           DOUBLE PRECISION,
    duration_seconds INTEGER,
    distance_meters  DOUBLE PRECISION,
    position         INTEGER       NOT NULL
);
