-- name: GetContent :one
SELECT id, site_id, value, 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, value, 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, value, 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, value, type, last_edited_by)
VALUES (sqlc.arg(id), sqlc.arg(site_id), sqlc.arg(value), sqlc.arg(type), sqlc.arg(last_edited_by))
RETURNING id, site_id, value, type, created_at, updated_at, last_edited_by;

-- name: UpdateContent :one
UPDATE content 
SET value = sqlc.arg(value), 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, value, type, created_at, updated_at, last_edited_by;

-- name: UpsertContent :one
INSERT INTO content (id, site_id, value, type, last_edited_by)
VALUES (sqlc.arg(id), sqlc.arg(site_id), sqlc.arg(value), sqlc.arg(type), sqlc.arg(last_edited_by))
ON CONFLICT(id, site_id) DO UPDATE SET
    value = EXCLUDED.value,
    type = EXCLUDED.type,
    last_edited_by = EXCLUDED.last_edited_by
RETURNING id, site_id, value, 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);