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

package gen

import (
	"context"
	"time"
)

const deleteLegacyPRComments = `-- name: DeleteLegacyPRComments :exec
DELETE FROM pr_comment WHERE pr_url = ? AND thread_id = ''
`

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

const deletePRComments = `-- name: DeletePRComments :exec
DELETE FROM pr_comment WHERE pr_url = ?
`

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

const deletePRCommentsByThread = `-- name: DeletePRCommentsByThread :exec
DELETE FROM pr_comment WHERE pr_url = ? AND thread_id = ?
`

type DeletePRCommentsByThreadParams struct {
	PRURL    string
	ThreadID string
}

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

const insertLegacyPRComment = `-- name: InsertLegacyPRComment :exec
INSERT OR IGNORE INTO pr_comment (pr_url, comment_id, author, file, line, body, resolved, created_at, thread_id, url, is_bot)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`

type InsertLegacyPRCommentParams struct {
	PRURL     string
	CommentID string
	Author    string
	File      string
	Line      int64
	Body      string
	Resolved  bool
	CreatedAt time.Time
	ThreadID  string
	URL       string
	IsBot     int64
}

func (q *Queries) InsertLegacyPRComment(ctx context.Context, arg InsertLegacyPRCommentParams) error {
	_, err := q.db.ExecContext(ctx, insertLegacyPRComment,
		arg.PRURL,
		arg.CommentID,
		arg.Author,
		arg.File,
		arg.Line,
		arg.Body,
		arg.Resolved,
		arg.CreatedAt,
		arg.ThreadID,
		arg.URL,
		arg.IsBot,
	)
	return err
}

const insertPRComment = `-- name: InsertPRComment :exec
INSERT INTO pr_comment (pr_url, comment_id, author, file, line, body, resolved, created_at, thread_id, url, is_bot)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`

type InsertPRCommentParams struct {
	PRURL     string
	CommentID string
	Author    string
	File      string
	Line      int64
	Body      string
	Resolved  bool
	CreatedAt time.Time
	ThreadID  string
	URL       string
	IsBot     int64
}

func (q *Queries) InsertPRComment(ctx context.Context, arg InsertPRCommentParams) error {
	_, err := q.db.ExecContext(ctx, insertPRComment,
		arg.PRURL,
		arg.CommentID,
		arg.Author,
		arg.File,
		arg.Line,
		arg.Body,
		arg.Resolved,
		arg.CreatedAt,
		arg.ThreadID,
		arg.URL,
		arg.IsBot,
	)
	return err
}

const listPRComments = `-- name: ListPRComments :many
SELECT pr_url, comment_id, author, file, line, body, resolved, created_at, thread_id, url, is_bot
FROM pr_comment WHERE pr_url = ? ORDER BY created_at, comment_id
`

func (q *Queries) ListPRComments(ctx context.Context, prUrl string) ([]PRComment, error) {
	rows, err := q.db.QueryContext(ctx, listPRComments, prUrl)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []PRComment{}
	for rows.Next() {
		var i PRComment
		if err := rows.Scan(
			&i.PRURL,
			&i.CommentID,
			&i.Author,
			&i.File,
			&i.Line,
			&i.Body,
			&i.Resolved,
			&i.CreatedAt,
			&i.ThreadID,
			&i.URL,
			&i.IsBot,
		); 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
}
