-- name: CreateProgram :one INSERT INTO programs ( course_id, title, description, thumbnail, display_order, is_active ) VALUES ($1, $2, $3, $4, COALESCE($5, 0), COALESCE($6, true)) RETURNING *; -- name: GetProgramsByCourse :many SELECT COUNT(*) OVER () AS total_count, id, course_id, title, description, thumbnail, display_order, is_active FROM programs WHERE course_id = $1 ORDER BY display_order ASC; -- name: UpdateProgramPartial :exec UPDATE programs SET title = COALESCE($1, title), description = COALESCE($2, description), thumbnail = COALESCE($3, thumbnail), display_order = COALESCE($4, display_order), is_active = COALESCE($5, is_active) WHERE id = $6; -- name: DeleteProgram :one DELETE FROM programs WHERE id = $1 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: UpdateProgramFull :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;