-- name: CreateReportedIssue :one
INSERT INTO reported_issues (
        user_id,
        user_role,
        subject,
        description,
        issue_type,
        metadata
    )
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING *;
-- name: ListReportedIssues :many
SELECT *
FROM reported_issues
ORDER BY created_at DESC
LIMIT $1 OFFSET $2;
-- name: ListReportedIssuesByUser :many
SELECT *
FROM reported_issues
WHERE user_id = $1
ORDER BY created_at DESC
LIMIT $2 OFFSET $3;
-- name: CountReportedIssues :one
SELECT COUNT(*)
FROM reported_issues;
-- name: CountReportedIssuesByUser :one
SELECT COUNT(*)
FROM reported_issues
WHERE user_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;

-- name: GetReportedIssueByID :one
SELECT * FROM reported_issues WHERE id = $1;