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

-- name: GetCourseByID :one
SELECT
    id,
    category_id,
    title,
    description,
    is_active
FROM courses
WHERE id = $1;

-- name: ListCoursesByCategory :many
SELECT
    id,
    category_id,
    title,
    description,
    is_active
FROM courses
WHERE category_id = $1
  AND is_active = TRUE
ORDER BY id DESC;

-- name: ListActiveCourses :many
SELECT
    id,
    category_id,
    title,
    description,
    is_active
FROM courses
WHERE is_active = TRUE
ORDER BY id DESC;

-- name: UpdateCourse :one
UPDATE courses
SET
    category_id = $2,
    title = $3,
    description = $4,
    is_active = $5
WHERE id = $1
RETURNING
    id,
    category_id,
    title,
    description,
    is_active;

-- name: DeactivateCourse :exec
UPDATE courses
SET is_active = FALSE
WHERE id = $1;

