-- name: CreateCourseCategory :one
INSERT INTO course_categories (
    name,
    is_active
)
VALUES ($1, COALESCE($2, true))
RETURNING *;


-- name: GetCourseCategoryByID :one
SELECT *
FROM course_categories
WHERE id = $1;


-- name: GetAllCourseCategories :many
SELECT
    COUNT(*) OVER () AS total_count,
    id,
    name,
    is_active,
    created_at
FROM course_categories
ORDER BY created_at DESC
LIMIT sqlc.narg('limit')::INT
OFFSET sqlc.narg('offset')::INT;


-- name: UpdateCourseCategory :exec
UPDATE course_categories
SET
    name = COALESCE($1, name),
    is_active = COALESCE($2, is_active)
WHERE id = $3;


-- name: DeleteCourseCategory :exec
DELETE FROM course_categories
WHERE id = $1;
