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

package db

import (
	"context"

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

const createTaskMessage = `-- name: CreateTaskMessage :one
INSERT INTO task_message (task_id, seq, type, tool, content, input, output)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id, task_id, seq, type, tool, content, input, output, created_at
`

type CreateTaskMessageParams struct {
	TaskID  pgtype.UUID `json:"task_id"`
	Seq     int32       `json:"seq"`
	Type    string      `json:"type"`
	Tool    pgtype.Text `json:"tool"`
	Content pgtype.Text `json:"content"`
	Input   []byte      `json:"input"`
	Output  pgtype.Text `json:"output"`
}

func (q *Queries) CreateTaskMessage(ctx context.Context, arg CreateTaskMessageParams) (TaskMessage, error) {
	row := q.db.QueryRow(ctx, createTaskMessage,
		arg.TaskID,
		arg.Seq,
		arg.Type,
		arg.Tool,
		arg.Content,
		arg.Input,
		arg.Output,
	)
	var i TaskMessage
	err := row.Scan(
		&i.ID,
		&i.TaskID,
		&i.Seq,
		&i.Type,
		&i.Tool,
		&i.Content,
		&i.Input,
		&i.Output,
		&i.CreatedAt,
	)
	return i, err
}

const deleteTaskMessages = `-- name: DeleteTaskMessages :exec
DELETE FROM task_message
WHERE task_id = $1
`

func (q *Queries) DeleteTaskMessages(ctx context.Context, taskID pgtype.UUID) error {
	_, err := q.db.Exec(ctx, deleteTaskMessages, taskID)
	return err
}

const listTaskMessages = `-- name: ListTaskMessages :many
SELECT id, task_id, seq, type, tool, content, input, output, created_at FROM task_message
WHERE task_id = $1
ORDER BY seq ASC
`

func (q *Queries) ListTaskMessages(ctx context.Context, taskID pgtype.UUID) ([]TaskMessage, error) {
	rows, err := q.db.Query(ctx, listTaskMessages, taskID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []TaskMessage{}
	for rows.Next() {
		var i TaskMessage
		if err := rows.Scan(
			&i.ID,
			&i.TaskID,
			&i.Seq,
			&i.Type,
			&i.Tool,
			&i.Content,
			&i.Input,
			&i.Output,
			&i.CreatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const listTaskMessagesSince = `-- name: ListTaskMessagesSince :many
SELECT id, task_id, seq, type, tool, content, input, output, created_at FROM task_message
WHERE task_id = $1 AND seq > $2
ORDER BY seq ASC
`

type ListTaskMessagesSinceParams struct {
	TaskID pgtype.UUID `json:"task_id"`
	Seq    int32       `json:"seq"`
}

func (q *Queries) ListTaskMessagesSince(ctx context.Context, arg ListTaskMessagesSinceParams) ([]TaskMessage, error) {
	rows, err := q.db.Query(ctx, listTaskMessagesSince, arg.TaskID, arg.Seq)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []TaskMessage{}
	for rows.Next() {
		var i TaskMessage
		if err := rows.Scan(
			&i.ID,
			&i.TaskID,
			&i.Seq,
			&i.Type,
			&i.Tool,
			&i.Content,
			&i.Input,
			&i.Output,
			&i.CreatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}
