// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.30.0
// source: issue_reporting.sql

package dbgen

import (
	"context"
)

const CountReportedIssues = `-- name: CountReportedIssues :one
SELECT COUNT(*)
FROM reported_issues
`

func (q *Queries) CountReportedIssues(ctx context.Context) (int64, error) {
	row := q.db.QueryRow(ctx, CountReportedIssues)
	var count int64
	err := row.Scan(&count)
	return count, err
}

const CountReportedIssuesByUser = `-- name: CountReportedIssuesByUser :one
SELECT COUNT(*)
FROM reported_issues
WHERE user_id = $1
`

func (q *Queries) CountReportedIssuesByUser(ctx context.Context, userID int64) (int64, error) {
	row := q.db.QueryRow(ctx, CountReportedIssuesByUser, userID)
	var count int64
	err := row.Scan(&count)
	return count, err
}

const CreateReportedIssue = `-- name: CreateReportedIssue :one
INSERT INTO reported_issues (
        user_id,
        user_role,
        subject,
        description,
        issue_type,
        metadata
    )
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id, user_id, user_role, subject, description, issue_type, status, metadata, created_at, updated_at
`

type CreateReportedIssueParams struct {
	UserID      int64  `json:"user_id"`
	UserRole    string `json:"user_role"`
	Subject     string `json:"subject"`
	Description string `json:"description"`
	IssueType   string `json:"issue_type"`
	Metadata    []byte `json:"metadata"`
}

func (q *Queries) CreateReportedIssue(ctx context.Context, arg CreateReportedIssueParams) (ReportedIssue, error) {
	row := q.db.QueryRow(ctx, CreateReportedIssue,
		arg.UserID,
		arg.UserRole,
		arg.Subject,
		arg.Description,
		arg.IssueType,
		arg.Metadata,
	)
	var i ReportedIssue
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.UserRole,
		&i.Subject,
		&i.Description,
		&i.IssueType,
		&i.Status,
		&i.Metadata,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

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

func (q *Queries) DeleteReportedIssue(ctx context.Context, id int64) error {
	_, err := q.db.Exec(ctx, DeleteReportedIssue, id)
	return err
}

const GetReportedIssueByID = `-- name: GetReportedIssueByID :one
SELECT id, user_id, user_role, subject, description, issue_type, status, metadata, created_at, updated_at FROM reported_issues WHERE id = $1
`

func (q *Queries) GetReportedIssueByID(ctx context.Context, id int64) (ReportedIssue, error) {
	row := q.db.QueryRow(ctx, GetReportedIssueByID, id)
	var i ReportedIssue
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.UserRole,
		&i.Subject,
		&i.Description,
		&i.IssueType,
		&i.Status,
		&i.Metadata,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const ListReportedIssues = `-- name: ListReportedIssues :many
SELECT id, user_id, user_role, subject, description, issue_type, status, metadata, created_at, updated_at
FROM reported_issues
ORDER BY created_at DESC
LIMIT $1 OFFSET $2
`

type ListReportedIssuesParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

func (q *Queries) ListReportedIssues(ctx context.Context, arg ListReportedIssuesParams) ([]ReportedIssue, error) {
	rows, err := q.db.Query(ctx, ListReportedIssues, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []ReportedIssue
	for rows.Next() {
		var i ReportedIssue
		if err := rows.Scan(
			&i.ID,
			&i.UserID,
			&i.UserRole,
			&i.Subject,
			&i.Description,
			&i.IssueType,
			&i.Status,
			&i.Metadata,
			&i.CreatedAt,
			&i.UpdatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const ListReportedIssuesByUser = `-- name: ListReportedIssuesByUser :many
SELECT id, user_id, user_role, subject, description, issue_type, status, metadata, created_at, updated_at
FROM reported_issues
WHERE user_id = $1
ORDER BY created_at DESC
LIMIT $2 OFFSET $3
`

type ListReportedIssuesByUserParams struct {
	UserID int64 `json:"user_id"`
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

func (q *Queries) ListReportedIssuesByUser(ctx context.Context, arg ListReportedIssuesByUserParams) ([]ReportedIssue, error) {
	rows, err := q.db.Query(ctx, ListReportedIssuesByUser, arg.UserID, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []ReportedIssue
	for rows.Next() {
		var i ReportedIssue
		if err := rows.Scan(
			&i.ID,
			&i.UserID,
			&i.UserRole,
			&i.Subject,
			&i.Description,
			&i.IssueType,
			&i.Status,
			&i.Metadata,
			&i.CreatedAt,
			&i.UpdatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

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

type UpdateReportedIssueStatusParams struct {
	ID     int64  `json:"id"`
	Status string `json:"status"`
}

func (q *Queries) UpdateReportedIssueStatus(ctx context.Context, arg UpdateReportedIssueStatusParams) error {
	_, err := q.db.Exec(ctx, UpdateReportedIssueStatus, arg.ID, arg.Status)
	return err
}
