// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.30.0
// source: todo.sql

package db

import (
	"context"

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

const createTodo = `-- name: CreateTodo :one
insert into todo (id,task) values ($1,$2) returning id, task, created_at, updated_at, done
`

type CreateTodoParams struct {
	ID   pgtype.UUID
	Task string
}

func (q *Queries) CreateTodo(ctx context.Context, arg CreateTodoParams) (Todo, error) {
	row := q.db.QueryRow(ctx, createTodo, arg.ID, arg.Task)
	var i Todo
	err := row.Scan(
		&i.ID,
		&i.Task,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.Done,
	)
	return i, err
}

const deleteTodo = `-- name: DeleteTodo :exec
delete from todo where id = $1
`

func (q *Queries) DeleteTodo(ctx context.Context, id pgtype.UUID) error {
	_, err := q.db.Exec(ctx, deleteTodo, id)
	return err
}

const getTodo = `-- name: GetTodo :one
select id, task, created_at, updated_at, done from todo where id = $1 limit 1
`

func (q *Queries) GetTodo(ctx context.Context, id pgtype.UUID) (Todo, error) {
	row := q.db.QueryRow(ctx, getTodo, id)
	var i Todo
	err := row.Scan(
		&i.ID,
		&i.Task,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.Done,
	)
	return i, err
}

const listTodos = `-- name: ListTodos :many
select id, task, created_at, updated_at, done from todo
`

func (q *Queries) ListTodos(ctx context.Context) ([]Todo, error) {
	rows, err := q.db.Query(ctx, listTodos)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Todo
	for rows.Next() {
		var i Todo
		if err := rows.Scan(
			&i.ID,
			&i.Task,
			&i.CreatedAt,
			&i.UpdatedAt,
			&i.Done,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const updateTodo = `-- name: UpdateTodo :one
update todo set task = $1, done = $2 where id = $3 returning id, task, created_at, updated_at, done
`

type UpdateTodoParams struct {
	Task string
	Done pgtype.Bool
	ID   pgtype.UUID
}

func (q *Queries) UpdateTodo(ctx context.Context, arg UpdateTodoParams) (Todo, error) {
	row := q.db.QueryRow(ctx, updateTodo, arg.Task, arg.Done, arg.ID)
	var i Todo
	err := row.Scan(
		&i.ID,
		&i.Task,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.Done,
	)
	return i, err
}
