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

package db

import (
	"context"

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

const closeTask = `-- name: CloseTask :one
UPDATE tasks
SET deleted_at = $1, assignee = $2
WHERE messageID = $3
RETURNING id, creator, creator_link, messageid, description, assignee, created_at, deleted_at, updated_at
`

type CloseTaskParams struct {
	DeletedAt pgtype.Timestamptz
	Assignee  pgtype.Text
	Messageid pgtype.Text
}

func (q *Queries) CloseTask(ctx context.Context, arg CloseTaskParams) (Task, error) {
	row := q.db.QueryRow(ctx, closeTask, arg.DeletedAt, arg.Assignee, arg.Messageid)
	var i Task
	err := row.Scan(
		&i.ID,
		&i.Creator,
		&i.CreatorLink,
		&i.Messageid,
		&i.Description,
		&i.Assignee,
		&i.CreatedAt,
		&i.DeletedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const createTicket = `-- name: CreateTicket :one
INSERT INTO tickets (
    key, channelID, title
) VALUES (
    $1, $2, $3
    )
    RETURNING id, key, channelid, project_git, build_git, folder, created_at, deleted_at, updated_at, title
`

type CreateTicketParams struct {
	Key       pgtype.Text
	Channelid pgtype.Text
	Title     pgtype.Text
}

func (q *Queries) CreateTicket(ctx context.Context, arg CreateTicketParams) (Ticket, error) {
	row := q.db.QueryRow(ctx, createTicket, arg.Key, arg.Channelid, arg.Title)
	var i Ticket
	err := row.Scan(
		&i.ID,
		&i.Key,
		&i.Channelid,
		&i.ProjectGit,
		&i.BuildGit,
		&i.Folder,
		&i.CreatedAt,
		&i.DeletedAt,
		&i.UpdatedAt,
		&i.Title,
	)
	return i, err
}

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 getConfig = `-- name: GetConfig :one
SELECT ticket_key, ticket_id
FROM appconfig
`

func (q *Queries) GetConfig(ctx context.Context) (Appconfig, error) {
	row := q.db.QueryRow(ctx, getConfig)
	var i Appconfig
	err := row.Scan(&i.TicketKey, &i.TicketID)
	return i, err
}

const getTaskByID = `-- name: GetTaskByID :one
SELECT id, creator, creator_link, messageid, description, assignee, created_at, deleted_at, updated_at FROM tasks WHERE id = $1
`

func (q *Queries) GetTaskByID(ctx context.Context, id int32) (Task, error) {
	row := q.db.QueryRow(ctx, getTaskByID, id)
	var i Task
	err := row.Scan(
		&i.ID,
		&i.Creator,
		&i.CreatorLink,
		&i.Messageid,
		&i.Description,
		&i.Assignee,
		&i.CreatedAt,
		&i.DeletedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const getTaskByMessage = `-- name: GetTaskByMessage :one
SELECT id, creator, creator_link, messageid, description, assignee, created_at, deleted_at, updated_at FROM tasks WHERE messageID = $1
`

func (q *Queries) GetTaskByMessage(ctx context.Context, messageid pgtype.Text) (Task, error) {
	row := q.db.QueryRow(ctx, getTaskByMessage, messageid)
	var i Task
	err := row.Scan(
		&i.ID,
		&i.Creator,
		&i.CreatorLink,
		&i.Messageid,
		&i.Description,
		&i.Assignee,
		&i.CreatedAt,
		&i.DeletedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const getTicketByChannelID = `-- name: GetTicketByChannelID :one
SELECT id, key, channelid, project_git, build_git, folder, created_at, deleted_at, updated_at, title FROM tickets WHERE channelID = $1
`

func (q *Queries) GetTicketByChannelID(ctx context.Context, channelid pgtype.Text) (Ticket, error) {
	row := q.db.QueryRow(ctx, getTicketByChannelID, channelid)
	var i Ticket
	err := row.Scan(
		&i.ID,
		&i.Key,
		&i.Channelid,
		&i.ProjectGit,
		&i.BuildGit,
		&i.Folder,
		&i.CreatedAt,
		&i.DeletedAt,
		&i.UpdatedAt,
		&i.Title,
	)
	return i, err
}

const getTicketByID = `-- name: GetTicketByID :one
SELECT id, key, channelid, project_git, build_git, folder, created_at, deleted_at, updated_at, title 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.Channelid,
		&i.ProjectGit,
		&i.BuildGit,
		&i.Folder,
		&i.CreatedAt,
		&i.DeletedAt,
		&i.UpdatedAt,
		&i.Title,
	)
	return i, err
}

const insertTask = `-- name: InsertTask :one
INSERT INTO tasks (
    creator, creator_link, description
) VALUES (
    $1, $2, $3
    )
    RETURNING id, creator, creator_link, messageid, description, assignee, created_at, deleted_at, updated_at
`

type InsertTaskParams struct {
	Creator     pgtype.Text
	CreatorLink pgtype.Text
	Description pgtype.Text
}

func (q *Queries) InsertTask(ctx context.Context, arg InsertTaskParams) (Task, error) {
	row := q.db.QueryRow(ctx, insertTask, arg.Creator, arg.CreatorLink, arg.Description)
	var i Task
	err := row.Scan(
		&i.ID,
		&i.Creator,
		&i.CreatorLink,
		&i.Messageid,
		&i.Description,
		&i.Assignee,
		&i.CreatedAt,
		&i.DeletedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const listTasksByCreator = `-- name: ListTasksByCreator :many
SELECT id, creator, creator_link, messageid, description, assignee, created_at, deleted_at, updated_at FROM tasks WHERE creator_link = $1 AND deleted_at is NULL
`

func (q *Queries) ListTasksByCreator(ctx context.Context, creatorLink pgtype.Text) ([]Task, error) {
	rows, err := q.db.Query(ctx, listTasksByCreator, creatorLink)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Task
	for rows.Next() {
		var i Task
		if err := rows.Scan(
			&i.ID,
			&i.Creator,
			&i.CreatorLink,
			&i.Messageid,
			&i.Description,
			&i.Assignee,
			&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 listTickets = `-- name: ListTickets :many
SELECT id, key, channelid, project_git, build_git, folder, created_at, deleted_at, updated_at, title 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.Channelid,
			&i.ProjectGit,
			&i.BuildGit,
			&i.Folder,
			&i.CreatedAt,
			&i.DeletedAt,
			&i.UpdatedAt,
			&i.Title,
		); 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, channelid, project_git, build_git, folder, created_at, deleted_at, updated_at, title 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.Channelid,
			&i.ProjectGit,
			&i.BuildGit,
			&i.Folder,
			&i.CreatedAt,
			&i.DeletedAt,
			&i.UpdatedAt,
			&i.Title,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const setNewConfig = `-- name: SetNewConfig :one
UPDATE appconfig
SET ticket_id = ticket_id + 1
RETURNING ticket_key, ticket_id
`

func (q *Queries) SetNewConfig(ctx context.Context) (Appconfig, error) {
	row := q.db.QueryRow(ctx, setNewConfig)
	var i Appconfig
	err := row.Scan(&i.TicketKey, &i.TicketID)
	return i, err
}

const startTask = `-- name: StartTask :one
UPDATE tasks
SET updated_at = $1, assignee = $2
WHERE messageID = $3
RETURNING id, creator, creator_link, messageid, description, assignee, created_at, deleted_at, updated_at
`

type StartTaskParams struct {
	UpdatedAt pgtype.Timestamptz
	Assignee  pgtype.Text
	Messageid pgtype.Text
}

func (q *Queries) StartTask(ctx context.Context, arg StartTaskParams) (Task, error) {
	row := q.db.QueryRow(ctx, startTask, arg.UpdatedAt, arg.Assignee, arg.Messageid)
	var i Task
	err := row.Scan(
		&i.ID,
		&i.Creator,
		&i.CreatorLink,
		&i.Messageid,
		&i.Description,
		&i.Assignee,
		&i.CreatedAt,
		&i.DeletedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const updateTaskWithMessageID = `-- name: UpdateTaskWithMessageID :exec
UPDATE tasks
SET messageID = $1
WHERE id = $2
`

type UpdateTaskWithMessageIDParams struct {
	Messageid pgtype.Text
	ID        int32
}

func (q *Queries) UpdateTaskWithMessageID(ctx context.Context, arg UpdateTaskWithMessageIDParams) error {
	_, err := q.db.Exec(ctx, updateTaskWithMessageID, arg.Messageid, arg.ID)
	return err
}

const updateTicketBuildGit = `-- name: UpdateTicketBuildGit :one
UPDATE tickets
SET build_git = $1, updated_at = $2
WHERE channelID = $3
RETURNING id, key, channelid, project_git, build_git, folder, created_at, deleted_at, updated_at, title
`

type UpdateTicketBuildGitParams struct {
	BuildGit  pgtype.Text
	UpdatedAt pgtype.Timestamptz
	Channelid pgtype.Text
}

func (q *Queries) UpdateTicketBuildGit(ctx context.Context, arg UpdateTicketBuildGitParams) (Ticket, error) {
	row := q.db.QueryRow(ctx, updateTicketBuildGit, arg.BuildGit, arg.UpdatedAt, arg.Channelid)
	var i Ticket
	err := row.Scan(
		&i.ID,
		&i.Key,
		&i.Channelid,
		&i.ProjectGit,
		&i.BuildGit,
		&i.Folder,
		&i.CreatedAt,
		&i.DeletedAt,
		&i.UpdatedAt,
		&i.Title,
	)
	return i, err
}

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
}

const updateTicketFolder = `-- name: UpdateTicketFolder :one
UPDATE tickets
SET folder = $1, updated_at = $2
WHERE channelID = $3
RETURNING id, key, channelid, project_git, build_git, folder, created_at, deleted_at, updated_at, title
`

type UpdateTicketFolderParams struct {
	Folder    pgtype.Text
	UpdatedAt pgtype.Timestamptz
	Channelid pgtype.Text
}

func (q *Queries) UpdateTicketFolder(ctx context.Context, arg UpdateTicketFolderParams) (Ticket, error) {
	row := q.db.QueryRow(ctx, updateTicketFolder, arg.Folder, arg.UpdatedAt, arg.Channelid)
	var i Ticket
	err := row.Scan(
		&i.ID,
		&i.Key,
		&i.Channelid,
		&i.ProjectGit,
		&i.BuildGit,
		&i.Folder,
		&i.CreatedAt,
		&i.DeletedAt,
		&i.UpdatedAt,
		&i.Title,
	)
	return i, err
}

const updateTicketProjectGit = `-- name: UpdateTicketProjectGit :one
UPDATE tickets
SET project_git = $1, updated_at = $2
WHERE channelID = $3
RETURNING id, key, channelid, project_git, build_git, folder, created_at, deleted_at, updated_at, title
`

type UpdateTicketProjectGitParams struct {
	ProjectGit pgtype.Text
	UpdatedAt  pgtype.Timestamptz
	Channelid  pgtype.Text
}

func (q *Queries) UpdateTicketProjectGit(ctx context.Context, arg UpdateTicketProjectGitParams) (Ticket, error) {
	row := q.db.QueryRow(ctx, updateTicketProjectGit, arg.ProjectGit, arg.UpdatedAt, arg.Channelid)
	var i Ticket
	err := row.Scan(
		&i.ID,
		&i.Key,
		&i.Channelid,
		&i.ProjectGit,
		&i.BuildGit,
		&i.Folder,
		&i.CreatedAt,
		&i.DeletedAt,
		&i.UpdatedAt,
		&i.Title,
	)
	return i, err
}
