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


-- name: GetModulesByLevel :many
SELECT
    COUNT(*) OVER () AS total_count,
    id,
    level_id,
    title,
    content,
    display_order,
    is_active
FROM modules
WHERE level_id = $1
ORDER BY display_order ASC;


-- name: UpdateModule :exec
UPDATE modules
SET
    title = COALESCE($1, title),
    content = COALESCE($2, content),
    display_order = COALESCE($3, display_order),
    is_active = COALESCE($4, is_active)
WHERE id = $5;


-- name: DeleteModule :exec
DELETE FROM modules
WHERE id = $1;
