-- name: CreateModule :one
INSERT INTO modules (
    level_id,
    title,
    content,
    display_order,
    is_active
)
VALUES (
    $1, -- level_id
    $2, -- title
    $3, -- content
    $4, -- display_order
    $5  -- is_active
)
RETURNING
    id,
    level_id,
    title,
    content,
    display_order,
    is_active;

-- name: GetModuleByID :one
SELECT
    id,
    level_id,
    title,
    content,
    display_order,
    is_active
FROM modules
WHERE id = $1;

-- name: ListModulesByLevel :many
SELECT
    id,
    level_id,
    title,
    content,
    display_order,
    is_active
FROM modules
WHERE level_id = $1
  AND is_active = TRUE
ORDER BY display_order ASC, id ASC;

-- name: UpdateModule :one
UPDATE modules
SET
    title = $2,
    content = $3,
    display_order = $4,
    is_active = $5
WHERE id = $1
RETURNING
    id,
    level_id,
    title,
    content,
    display_order,
    is_active;

-- name: DeactivateModule :exec
UPDATE modules
SET is_active = FALSE
WHERE id = $1;
