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

package sqlc

import (
	"context"

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

const createSubagent = `-- name: CreateSubagent :one
INSERT INTO subagents (name, description, bot_id, messages, metadata, skills)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id, name, description, created_at, updated_at, deleted, deleted_at, bot_id, messages, metadata, skills, usage
`

type CreateSubagentParams struct {
	Name        string      `json:"name"`
	Description string      `json:"description"`
	BotID       pgtype.UUID `json:"bot_id"`
	Messages    []byte      `json:"messages"`
	Metadata    []byte      `json:"metadata"`
	Skills      []byte      `json:"skills"`
}

func (q *Queries) CreateSubagent(ctx context.Context, arg CreateSubagentParams) (Subagent, error) {
	row := q.db.QueryRow(ctx, createSubagent,
		arg.Name,
		arg.Description,
		arg.BotID,
		arg.Messages,
		arg.Metadata,
		arg.Skills,
	)
	var i Subagent
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Description,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.Deleted,
		&i.DeletedAt,
		&i.BotID,
		&i.Messages,
		&i.Metadata,
		&i.Skills,
		&i.Usage,
	)
	return i, err
}

const getSubagentByBotAndName = `-- name: GetSubagentByBotAndName :one
SELECT id, name, description, created_at, updated_at, deleted, deleted_at, bot_id, messages, metadata, skills, usage
FROM subagents
WHERE bot_id = $1 AND name = $2 AND deleted = false
`

type GetSubagentByBotAndNameParams struct {
	BotID pgtype.UUID `json:"bot_id"`
	Name  string      `json:"name"`
}

func (q *Queries) GetSubagentByBotAndName(ctx context.Context, arg GetSubagentByBotAndNameParams) (Subagent, error) {
	row := q.db.QueryRow(ctx, getSubagentByBotAndName, arg.BotID, arg.Name)
	var i Subagent
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Description,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.Deleted,
		&i.DeletedAt,
		&i.BotID,
		&i.Messages,
		&i.Metadata,
		&i.Skills,
		&i.Usage,
	)
	return i, err
}

const getSubagentByID = `-- name: GetSubagentByID :one
SELECT id, name, description, created_at, updated_at, deleted, deleted_at, bot_id, messages, metadata, skills, usage
FROM subagents
WHERE id = $1 AND deleted = false
`

func (q *Queries) GetSubagentByID(ctx context.Context, id pgtype.UUID) (Subagent, error) {
	row := q.db.QueryRow(ctx, getSubagentByID, id)
	var i Subagent
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Description,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.Deleted,
		&i.DeletedAt,
		&i.BotID,
		&i.Messages,
		&i.Metadata,
		&i.Skills,
		&i.Usage,
	)
	return i, err
}

const listSubagentsByBot = `-- name: ListSubagentsByBot :many
SELECT id, name, description, created_at, updated_at, deleted, deleted_at, bot_id, messages, metadata, skills, usage
FROM subagents
WHERE bot_id = $1 AND deleted = false
ORDER BY created_at DESC
`

func (q *Queries) ListSubagentsByBot(ctx context.Context, botID pgtype.UUID) ([]Subagent, error) {
	rows, err := q.db.Query(ctx, listSubagentsByBot, botID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Subagent
	for rows.Next() {
		var i Subagent
		if err := rows.Scan(
			&i.ID,
			&i.Name,
			&i.Description,
			&i.CreatedAt,
			&i.UpdatedAt,
			&i.Deleted,
			&i.DeletedAt,
			&i.BotID,
			&i.Messages,
			&i.Metadata,
			&i.Skills,
			&i.Usage,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const softDeleteSubagent = `-- name: SoftDeleteSubagent :exec
UPDATE subagents
SET deleted = true,
    deleted_at = now(),
    updated_at = now()
WHERE id = $1 AND deleted = false
`

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

const updateSubagent = `-- name: UpdateSubagent :one
UPDATE subagents
SET name = $2,
    description = $3,
    metadata = $4,
    updated_at = now()
WHERE id = $1 AND deleted = false
RETURNING id, name, description, created_at, updated_at, deleted, deleted_at, bot_id, messages, metadata, skills, usage
`

type UpdateSubagentParams struct {
	ID          pgtype.UUID `json:"id"`
	Name        string      `json:"name"`
	Description string      `json:"description"`
	Metadata    []byte      `json:"metadata"`
}

func (q *Queries) UpdateSubagent(ctx context.Context, arg UpdateSubagentParams) (Subagent, error) {
	row := q.db.QueryRow(ctx, updateSubagent,
		arg.ID,
		arg.Name,
		arg.Description,
		arg.Metadata,
	)
	var i Subagent
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Description,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.Deleted,
		&i.DeletedAt,
		&i.BotID,
		&i.Messages,
		&i.Metadata,
		&i.Skills,
		&i.Usage,
	)
	return i, err
}

const updateSubagentMessages = `-- name: UpdateSubagentMessages :one
UPDATE subagents
SET messages = $2,
    updated_at = now()
WHERE id = $1 AND deleted = false
RETURNING id, name, description, created_at, updated_at, deleted, deleted_at, bot_id, messages, metadata, skills, usage
`

type UpdateSubagentMessagesParams struct {
	ID       pgtype.UUID `json:"id"`
	Messages []byte      `json:"messages"`
}

func (q *Queries) UpdateSubagentMessages(ctx context.Context, arg UpdateSubagentMessagesParams) (Subagent, error) {
	row := q.db.QueryRow(ctx, updateSubagentMessages, arg.ID, arg.Messages)
	var i Subagent
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Description,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.Deleted,
		&i.DeletedAt,
		&i.BotID,
		&i.Messages,
		&i.Metadata,
		&i.Skills,
		&i.Usage,
	)
	return i, err
}

const updateSubagentMessagesAndUsage = `-- name: UpdateSubagentMessagesAndUsage :one
UPDATE subagents
SET messages = $2,
    usage = $3,
    updated_at = now()
WHERE id = $1 AND deleted = false
RETURNING id, name, description, created_at, updated_at, deleted, deleted_at, bot_id, messages, metadata, skills, usage
`

type UpdateSubagentMessagesAndUsageParams struct {
	ID       pgtype.UUID `json:"id"`
	Messages []byte      `json:"messages"`
	Usage    []byte      `json:"usage"`
}

func (q *Queries) UpdateSubagentMessagesAndUsage(ctx context.Context, arg UpdateSubagentMessagesAndUsageParams) (Subagent, error) {
	row := q.db.QueryRow(ctx, updateSubagentMessagesAndUsage, arg.ID, arg.Messages, arg.Usage)
	var i Subagent
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Description,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.Deleted,
		&i.DeletedAt,
		&i.BotID,
		&i.Messages,
		&i.Metadata,
		&i.Skills,
		&i.Usage,
	)
	return i, err
}

const updateSubagentSkills = `-- name: UpdateSubagentSkills :one
UPDATE subagents
SET skills = $2,
    updated_at = now()
WHERE id = $1 AND deleted = false
RETURNING id, name, description, created_at, updated_at, deleted, deleted_at, bot_id, messages, metadata, skills, usage
`

type UpdateSubagentSkillsParams struct {
	ID     pgtype.UUID `json:"id"`
	Skills []byte      `json:"skills"`
}

func (q *Queries) UpdateSubagentSkills(ctx context.Context, arg UpdateSubagentSkillsParams) (Subagent, error) {
	row := q.db.QueryRow(ctx, updateSubagentSkills, arg.ID, arg.Skills)
	var i Subagent
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Description,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.Deleted,
		&i.DeletedAt,
		&i.BotID,
		&i.Messages,
		&i.Metadata,
		&i.Skills,
		&i.Usage,
	)
	return i, err
}
