// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.23.0
// source: tickets.sql

package store_tickets

import (
	"context"

	"github.com/jackc/pgx/v5/pgtype"
)

const deleteTicketByID = `-- name: DeleteTicketByID :exec
UPDATE tickets SET deleted_at = current_timestamp WHERE id = $1
`

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

const deleteTicketByKey = `-- name: DeleteTicketByKey :exec
UPDATE tickets SET deleted_at = current_timestamp WHERE key = $1
`

func (q *Queries) DeleteTicketByKey(ctx context.Context, key pgtype.Text) error {
	_, err := q.db.Exec(ctx, deleteTicketByKey, key)
	return err
}

const getTicketByID = `-- name: GetTicketByID :one
SELECT id, key, project_git, build_git, folder, created_at, deleted_at, updated_at FROM tickets WHERE id = $1
`

func (q *Queries) GetTicketByID(ctx context.Context, id int32) (Ticket, error) {
	row := q.db.QueryRow(ctx, getTicketByID, id)
	var i Ticket
	err := row.Scan(
		&i.ID,
		&i.Key,
		&i.ProjectGit,
		&i.BuildGit,
		&i.Folder,
		&i.CreatedAt,
		&i.DeletedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const listTickets = `-- name: ListTickets :many
SELECT id, key, project_git, build_git, folder, created_at, deleted_at, updated_at FROM tickets WHERE deleted_at IS NULL
`

func (q *Queries) ListTickets(ctx context.Context) ([]Ticket, error) {
	rows, err := q.db.Query(ctx, listTickets)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Ticket
	for rows.Next() {
		var i Ticket
		if err := rows.Scan(
			&i.ID,
			&i.Key,
			&i.ProjectGit,
			&i.BuildGit,
			&i.Folder,
			&i.CreatedAt,
			&i.DeletedAt,
			&i.UpdatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const listTicketsWithDeleted = `-- name: ListTicketsWithDeleted :many
SELECT id, key, project_git, build_git, folder, created_at, deleted_at, updated_at FROM tickets
`

func (q *Queries) ListTicketsWithDeleted(ctx context.Context) ([]Ticket, error) {
	rows, err := q.db.Query(ctx, listTicketsWithDeleted)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Ticket
	for rows.Next() {
		var i Ticket
		if err := rows.Scan(
			&i.ID,
			&i.Key,
			&i.ProjectGit,
			&i.BuildGit,
			&i.Folder,
			&i.CreatedAt,
			&i.DeletedAt,
			&i.UpdatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const updateTicketByID = `-- name: UpdateTicketByID :exec
UPDATE tickets SET project_git = $1, build_git = $2, folder = $3 WHERE id = $4
`

type UpdateTicketByIDParams struct {
	ProjectGit pgtype.Text
	BuildGit   pgtype.Text
	Folder     pgtype.Text
	ID         int32
}

func (q *Queries) UpdateTicketByID(ctx context.Context, arg UpdateTicketByIDParams) error {
	_, err := q.db.Exec(ctx, updateTicketByID,
		arg.ProjectGit,
		arg.BuildGit,
		arg.Folder,
		arg.ID,
	)
	return err
}
