-- name: GetContent :one
SELECT id, site_id, html_content, original_template, type, created_at, updated_at, last_edited_by
FROM content 
WHERE id = sqlc.arg(id) AND site_id = sqlc.arg(site_id);

-- name: GetAllContent :many
SELECT id, site_id, html_content, original_template, type, created_at, updated_at, last_edited_by
FROM content 
WHERE site_id = sqlc.arg(site_id)
ORDER BY updated_at DESC;

-- name: GetBulkContent :many
SELECT id, site_id, html_content, original_template, type, created_at, updated_at, last_edited_by
FROM content 
WHERE site_id = sqlc.arg(site_id) AND id IN (sqlc.slice('ids'));

-- name: CreateContent :one
INSERT INTO content (id, site_id, html_content, original_template, type, last_edited_by)
VALUES (sqlc.arg(id), sqlc.arg(site_id), sqlc.arg(html_content), sqlc.arg(original_template), sqlc.arg(type), sqlc.arg(last_edited_by))
RETURNING id, site_id, html_content, original_template, type, created_at, updated_at, last_edited_by;

-- name: UpdateContent :one
UPDATE content 
SET html_content = sqlc.arg(html_content), type = sqlc.arg(type), last_edited_by = sqlc.arg(last_edited_by)
WHERE id = sqlc.arg(id) AND site_id = sqlc.arg(site_id)
RETURNING id, site_id, html_content, original_template, type, created_at, updated_at, last_edited_by;

-- name: UpsertContent :one
INSERT INTO content (id, site_id, html_content, original_template, type, last_edited_by)
VALUES (sqlc.arg(id), sqlc.arg(site_id), sqlc.arg(html_content), sqlc.arg(original_template), sqlc.arg(type), sqlc.arg(last_edited_by))
ON CONFLICT(id, site_id) DO UPDATE SET
    html_content = EXCLUDED.html_content,
    type = EXCLUDED.type,
    last_edited_by = EXCLUDED.last_edited_by
RETURNING id, site_id, html_content, original_template, type, created_at, updated_at, last_edited_by;

-- name: DeleteContent :exec
DELETE FROM content 
WHERE id = sqlc.arg(id) AND site_id = sqlc.arg(site_id);

-- name: DeleteAllSiteContent :exec
DELETE FROM content 
WHERE site_id = sqlc.arg(site_id);