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

package gen

import (
	"context"
	"time"
)

const deletePRReviews = `-- name: DeletePRReviews :exec
DELETE FROM pr_reviews WHERE pr_url = ?
`

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

const listPRReviews = `-- name: ListPRReviews :many
SELECT pr_url, review_id, author, state, url, is_bot, submitted_at
FROM pr_reviews WHERE pr_url = ? ORDER BY submitted_at, review_id
`

func (q *Queries) ListPRReviews(ctx context.Context, prUrl string) ([]PRReview, error) {
	rows, err := q.db.QueryContext(ctx, listPRReviews, prUrl)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []PRReview{}
	for rows.Next() {
		var i PRReview
		if err := rows.Scan(
			&i.PRURL,
			&i.ReviewID,
			&i.Author,
			&i.State,
			&i.URL,
			&i.IsBot,
			&i.SubmittedAt,
		); 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 upsertPRReview = `-- name: UpsertPRReview :exec
INSERT INTO pr_reviews (pr_url, review_id, author, state, url, is_bot, submitted_at)
VALUES (?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (pr_url, review_id) DO UPDATE SET
    author = excluded.author,
    state = excluded.state,
    url = excluded.url,
    is_bot = excluded.is_bot,
    submitted_at = excluded.submitted_at
`

type UpsertPRReviewParams struct {
	PRURL       string
	ReviewID    string
	Author      string
	State       string
	URL         string
	IsBot       int64
	SubmittedAt time.Time
}

func (q *Queries) UpsertPRReview(ctx context.Context, arg UpsertPRReviewParams) error {
	_, err := q.db.ExecContext(ctx, upsertPRReview,
		arg.PRURL,
		arg.ReviewID,
		arg.Author,
		arg.State,
		arg.URL,
		arg.IsBot,
		arg.SubmittedAt,
	)
	return err
}
