-- name: CreateProgram :one
INSERT INTO programs (name, description, thumbnail)
VALUES ($1, $2, $3)
RETURNING *;

-- name: GetProgramByID :one
SELECT *
FROM programs
WHERE id = $1;

-- name: ListPrograms :many
SELECT
    COUNT(*) OVER () AS total_count,
    p.id,
    p.name,
    p.description,
    p.thumbnail,
    p.created_at,
    p.updated_at
FROM programs p
ORDER BY p.created_at DESC
LIMIT $1 OFFSET $2;

-- name: UpdateProgram :one
UPDATE programs
SET
    name = COALESCE(sqlc.narg('name')::varchar, name),
    description = COALESCE(sqlc.narg('description')::text, description),
    thumbnail = COALESCE(sqlc.narg('thumbnail')::text, thumbnail),
    updated_at = CURRENT_TIMESTAMP
WHERE id = sqlc.arg('id')
RETURNING *;

-- name: DeleteProgram :exec
DELETE FROM programs
WHERE id = $1;
