-- name: CreateCourse :one
INSERT INTO courses (
    category_id,
    title,
    description,
    is_active
)
VALUES ($1, $2, $3, COALESCE($4, true))
RETURNING *;


-- name: GetCourseByID :one
SELECT *
FROM courses
WHERE id = $1;


-- name: GetCoursesByCategory :many
SELECT
    COUNT(*) OVER () AS total_count,
    id,
    category_id,
    title,
    description,
    is_active
FROM courses
WHERE category_id = $1
ORDER BY id DESC
LIMIT sqlc.narg('limit')::INT
OFFSET sqlc.narg('offset')::INT;


-- name: UpdateCourse :exec
UPDATE courses
SET
    title = COALESCE($1, title),
    description = COALESCE($2, description),
    is_active = COALESCE($3, is_active)
WHERE id = $4;


-- name: DeleteCourse :exec
DELETE FROM courses
WHERE id = $1;
