-- name: CreateLevel :one
INSERT INTO levels (
    program_id,
    title,
    description,
    level_index,
    number_of_modules,
    number_of_practices,
    number_of_videos,
    is_active
)
VALUES (
    $1, -- program_id
    $2, -- title
    $3, -- description
    $4, -- level_index
    $5, -- number_of_modules
    $6, -- number_of_practices
    $7, -- number_of_videos
    $8  -- is_active
)
RETURNING
    id,
    program_id,
    title,
    description,
    level_index,
    number_of_modules,
    number_of_practices,
    number_of_videos,
    is_active;

-- name: GetLevelByID :one
SELECT
    id,
    program_id,
    title,
    description,
    level_index,
    number_of_modules,
    number_of_practices,
    number_of_videos,
    is_active
FROM levels
WHERE id = $1;

-- name: ListLevelsByProgram :many
SELECT
    id,
    program_id,
    title,
    description,
    level_index,
    number_of_modules,
    number_of_practices,
    number_of_videos,
    is_active
FROM levels
WHERE program_id = $1
  AND is_active = TRUE
ORDER BY level_index ASC;

-- name: UpdateLevel :one
UPDATE levels
SET
    title = $2,
    description = $3,
    level_index = $4,
    number_of_modules = $5,
    number_of_practices = $6,
    number_of_videos = $7,
    is_active = $8
WHERE id = $1
RETURNING
    id,
    program_id,
    title,
    description,
    level_index,
    number_of_modules,
    number_of_practices,
    number_of_videos,
    is_active;

-- name: DeactivateLevel :exec
UPDATE levels
SET is_active = FALSE
WHERE id = $1;
