// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.31.1
// source: pr_review_threads.sql

package gen

import (
	"context"
	"time"
)

const deletePRReviewThread = `-- name: DeletePRReviewThread :exec
DELETE FROM pr_review_threads WHERE pr_url = ? AND thread_id = ?
`

type DeletePRReviewThreadParams struct {
	PRURL    string
	ThreadID string
}

func (q *Queries) DeletePRReviewThread(ctx context.Context, arg DeletePRReviewThreadParams) error {
	_, err := q.db.ExecContext(ctx, deletePRReviewThread, arg.PRURL, arg.ThreadID)
	return err
}

const deletePRReviewThreads = `-- name: DeletePRReviewThreads :exec
DELETE FROM pr_review_threads WHERE pr_url = ?
`

func (q *Queries) DeletePRReviewThreads(ctx context.Context, prUrl string) error {
	_, err := q.db.ExecContext(ctx, deletePRReviewThreads, prUrl)
	return err
}

const listPRReviewThreads = `-- name: ListPRReviewThreads :many
SELECT pr_url, thread_id, path, line, resolved, is_bot, semantic_hash, updated_at
FROM pr_review_threads WHERE pr_url = ? ORDER BY updated_at, thread_id
`

func (q *Queries) ListPRReviewThreads(ctx context.Context, prUrl string) ([]PRReviewThread, error) {
	rows, err := q.db.QueryContext(ctx, listPRReviewThreads, prUrl)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []PRReviewThread{}
	for rows.Next() {
		var i PRReviewThread
		if err := rows.Scan(
			&i.PRURL,
			&i.ThreadID,
			&i.Path,
			&i.Line,
			&i.Resolved,
			&i.IsBot,
			&i.SemanticHash,
			&i.UpdatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const upsertPRReviewThread = `-- name: UpsertPRReviewThread :exec
INSERT INTO pr_review_threads (pr_url, thread_id, path, line, resolved, is_bot, semantic_hash, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (pr_url, thread_id) DO UPDATE SET
    path = excluded.path,
    line = excluded.line,
    resolved = excluded.resolved,
    is_bot = excluded.is_bot,
    semantic_hash = excluded.semantic_hash,
    updated_at = excluded.updated_at
`

type UpsertPRReviewThreadParams struct {
	PRURL        string
	ThreadID     string
	Path         string
	Line         int64
	Resolved     int64
	IsBot        int64
	SemanticHash string
	UpdatedAt    time.Time
}

// Summary: SQLC queries for replacing and reading normalized PR review threads.
func (q *Queries) UpsertPRReviewThread(ctx context.Context, arg UpsertPRReviewThreadParams) error {
	_, err := q.db.ExecContext(ctx, upsertPRReviewThread,
		arg.PRURL,
		arg.ThreadID,
		arg.Path,
		arg.Line,
		arg.Resolved,
		arg.IsBot,
		arg.SemanticHash,
		arg.UpdatedAt,
	)
	return err
}
