-- name: CreateAuditLog :exec
INSERT INTO audit_logs (
    operator_id,
    tenant_id,
    module,
    action,
    resource_type,
    resource_id,
    request_id,
    before_json,
    after_json,
    result,
    error_message
)
VALUES (sqlc.arg(operator_id), sqlc.arg(tenant_id), sqlc.arg(module), sqlc.arg(action),
        sqlc.arg(resource_type), sqlc.arg(resource_id), sqlc.arg(request_id),
        sqlc.arg(before_json), sqlc.arg(after_json), sqlc.arg(result), sqlc.arg(error_message));

-- name: CreateGenerationTask :one
INSERT INTO generation_tasks (tenant_id, operator_id, article_id, quota_reservation_id, task_type, input_params_json, status)
VALUES (sqlc.arg(tenant_id), sqlc.arg(operator_id), sqlc.arg(article_id), sqlc.arg(quota_reservation_id),
        sqlc.arg(task_type), sqlc.arg(input_params_json), 'queued')
RETURNING id;

-- name: UpdateGenerationTaskStatus :exec
UPDATE generation_tasks SET status = sqlc.arg(status), error_message = sqlc.arg(error_message),
       started_at = sqlc.arg(started_at), completed_at = sqlc.arg(completed_at), updated_at = NOW()
WHERE id = sqlc.arg(id) AND tenant_id = sqlc.arg(tenant_id);
