-- name: CreateReportedIssue :one
INSERT INTO reported_issues (
    customer_id, subject, description, issue_type, metadata
) VALUES (
    $1, $2, $3, $4, $5
)
RETURNING *;

-- name: ListReportedIssues :many
SELECT * FROM reported_issues
ORDER BY created_at DESC
LIMIT $1 OFFSET $2;

-- name: ListReportedIssuesByCustomer :many
SELECT * FROM reported_issues
WHERE customer_id = $1
ORDER BY created_at DESC
LIMIT $2 OFFSET $3;

-- name: CountReportedIssues :one
SELECT COUNT(*) FROM reported_issues;

-- name: CountReportedIssuesByCustomer :one
SELECT COUNT(*) FROM reported_issues WHERE customer_id = $1;

-- name: UpdateReportedIssueStatus :exec
UPDATE reported_issues
SET status = $2, updated_at = NOW()
WHERE id = $1;

-- name: DeleteReportedIssue :exec
DELETE FROM reported_issues WHERE id = $1;
