-- name: CreateModuleVideo :one
INSERT INTO module_videos (
    module_id,
    title,
    description,
    video_url,
    duration,
    resolution,
    instructor_id,
    thumbnail,
    visibility,
    is_active
)
VALUES (
    $1, $2, $3, $4, $5, $6,
    $7, $8, $9,
    COALESCE($10, true)
)
RETURNING *;


-- name: PublishModuleVideo :exec
UPDATE module_videos
SET
    is_published = true,
    publish_date = CURRENT_TIMESTAMP
WHERE id = $1;


-- name: GetPublishedVideosByModule :many
SELECT *
FROM module_videos
WHERE module_id = $1
  AND is_published = true
  AND is_active = true
ORDER BY publish_date ASC;


-- name: UpdateModuleVideo :exec
UPDATE module_videos
SET
    title = COALESCE($1, title),
    description = COALESCE($2, description),
    video_url = COALESCE($3, video_url),
    duration = COALESCE($4, duration),
    resolution = COALESCE($5, resolution),
    visibility = COALESCE($6, visibility),
    thumbnail = COALESCE($7, thumbnail),
    is_active = COALESCE($8, is_active)
WHERE id = $9;


-- name: DeleteModuleVideo :exec
DELETE FROM module_videos
WHERE id = $1;
