-- name: CreateProject :one
INSERT INTO projects (id, slug, name, description, visibility, owner_id)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id, slug, name, description, visibility, owner_id, archived_at, created_at, updated_at;

-- name: GetProjectBySlug :one
SELECT id, slug, name, description, visibility, owner_id, archived_at, created_at, updated_at
FROM projects WHERE slug = $1;

-- name: GetProjectByID :one
SELECT id, slug, name, description, visibility, owner_id, archived_at, created_at, updated_at
FROM projects WHERE id = $1;

-- name: ListProjects :many
SELECT id, slug, name, description, visibility, owner_id, archived_at, created_at, updated_at
FROM projects
WHERE (sqlc.arg('include_archived')::bool OR archived_at IS NULL)
ORDER BY created_at DESC;

-- name: UpdateProject :one
UPDATE projects
SET name        = $2,
    description = $3,
    visibility  = $4,
    updated_at  = now()
WHERE id = $1
RETURNING id, slug, name, description, visibility, owner_id, archived_at, created_at, updated_at;

-- name: ArchiveProject :exec
UPDATE projects SET archived_at = now(), updated_at = now()
WHERE id = $1 AND archived_at IS NULL;

-- name: UnarchiveProject :exec
UPDATE projects SET archived_at = NULL, updated_at = now()
WHERE id = $1 AND archived_at IS NOT NULL;
