-- name: CreateProgram :one
INSERT INTO programs (
    course_id,
    title,
    description,
    thumbnail,
    display_order,
    is_active
)
VALUES (
    $1, -- course_id
    $2, -- title
    $3, -- description
    $4, -- thumbnail
    $5, -- display_order
    $6  -- is_active
)
RETURNING
    id,
    course_id,
    title,
    description,
    thumbnail,
    display_order,
    is_active;

-- name: GetProgramByID :one
SELECT
    id,
    course_id,
    title,
    description,
    thumbnail,
    display_order,
    is_active
FROM programs
WHERE id = $1;

-- name: ListProgramsByCourse :many
SELECT
    id,
    course_id,
    title,
    description,
    thumbnail,
    display_order,
    is_active
FROM programs
WHERE course_id = $1
  AND is_active = TRUE
ORDER BY display_order ASC, id ASC;

-- name: ListActivePrograms :many
SELECT
    id,
    course_id,
    title,
    description,
    thumbnail,
    display_order,
    is_active
FROM programs
WHERE is_active = TRUE
ORDER BY display_order ASC;

-- name: UpdateProgram :one
UPDATE programs
SET
    course_id = $2,
    title = $3,
    description = $4,
    thumbnail = $5,
    display_order = $6,
    is_active = $7
WHERE id = $1
RETURNING
    id,
    course_id,
    title,
    description,
    thumbnail,
    display_order,
    is_active;

-- name: DeactivateProgram :exec
UPDATE programs
SET is_active = FALSE
WHERE id = $1;
