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

package acpsqlc

import (
	"context"

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

const countAgentKindUsage = `-- name: CountAgentKindUsage :one
SELECT COUNT(*) FROM acp_sessions WHERE agent_kind_id = $1
`

func (q *Queries) CountAgentKindUsage(ctx context.Context, agentKindID pgtype.UUID) (int64, error) {
	row := q.db.QueryRow(ctx, countAgentKindUsage, agentKindID)
	var count int64
	err := row.Scan(&count)
	return count, err
}

const createAgentKind = `-- name: CreateAgentKind :one
INSERT INTO acp_agent_kinds (
  id, name, display_name, description, binary_path, args, encrypted_env, enabled, created_by, tool_allowlist, client_type, encrypted_mcp_servers,
  model_id, max_cost_usd, max_tokens, max_wall_clock_seconds
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)
RETURNING id, name, display_name, description, binary_path, args, encrypted_env,
          enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers,
          model_id, max_cost_usd, max_tokens, max_wall_clock_seconds, key_version
`

type CreateAgentKindParams struct {
	ID                  pgtype.UUID    `json:"id"`
	Name                string         `json:"name"`
	DisplayName         string         `json:"display_name"`
	Description         string         `json:"description"`
	BinaryPath          string         `json:"binary_path"`
	Args                []string       `json:"args"`
	EncryptedEnv        []byte         `json:"encrypted_env"`
	Enabled             bool           `json:"enabled"`
	CreatedBy           pgtype.UUID    `json:"created_by"`
	ToolAllowlist       []string       `json:"tool_allowlist"`
	ClientType          string         `json:"client_type"`
	EncryptedMcpServers []byte         `json:"encrypted_mcp_servers"`
	ModelID             pgtype.UUID    `json:"model_id"`
	MaxCostUsd          pgtype.Numeric `json:"max_cost_usd"`
	MaxTokens           *int64         `json:"max_tokens"`
	MaxWallClockSeconds *int32         `json:"max_wall_clock_seconds"`
}

func (q *Queries) CreateAgentKind(ctx context.Context, arg CreateAgentKindParams) (AcpAgentKind, error) {
	row := q.db.QueryRow(ctx, createAgentKind,
		arg.ID,
		arg.Name,
		arg.DisplayName,
		arg.Description,
		arg.BinaryPath,
		arg.Args,
		arg.EncryptedEnv,
		arg.Enabled,
		arg.CreatedBy,
		arg.ToolAllowlist,
		arg.ClientType,
		arg.EncryptedMcpServers,
		arg.ModelID,
		arg.MaxCostUsd,
		arg.MaxTokens,
		arg.MaxWallClockSeconds,
	)
	var i AcpAgentKind
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.DisplayName,
		&i.Description,
		&i.BinaryPath,
		&i.Args,
		&i.EncryptedEnv,
		&i.Enabled,
		&i.CreatedBy,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.ToolAllowlist,
		&i.ClientType,
		&i.EncryptedMcpServers,
		&i.ModelID,
		&i.MaxCostUsd,
		&i.MaxTokens,
		&i.MaxWallClockSeconds,
		&i.KeyVersion,
	)
	return i, err
}

const deleteAgentKind = `-- name: DeleteAgentKind :exec
DELETE FROM acp_agent_kinds WHERE id = $1
`

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

const getAgentKindByID = `-- name: GetAgentKindByID :one
SELECT id, name, display_name, description, binary_path, args, encrypted_env,
       enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers,
       model_id, max_cost_usd, max_tokens, max_wall_clock_seconds, key_version
FROM acp_agent_kinds
WHERE id = $1
`

func (q *Queries) GetAgentKindByID(ctx context.Context, id pgtype.UUID) (AcpAgentKind, error) {
	row := q.db.QueryRow(ctx, getAgentKindByID, id)
	var i AcpAgentKind
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.DisplayName,
		&i.Description,
		&i.BinaryPath,
		&i.Args,
		&i.EncryptedEnv,
		&i.Enabled,
		&i.CreatedBy,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.ToolAllowlist,
		&i.ClientType,
		&i.EncryptedMcpServers,
		&i.ModelID,
		&i.MaxCostUsd,
		&i.MaxTokens,
		&i.MaxWallClockSeconds,
		&i.KeyVersion,
	)
	return i, err
}

const getAgentKindByName = `-- name: GetAgentKindByName :one
SELECT id, name, display_name, description, binary_path, args, encrypted_env,
       enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers,
       model_id, max_cost_usd, max_tokens, max_wall_clock_seconds, key_version
FROM acp_agent_kinds
WHERE name = $1
`

func (q *Queries) GetAgentKindByName(ctx context.Context, name string) (AcpAgentKind, error) {
	row := q.db.QueryRow(ctx, getAgentKindByName, name)
	var i AcpAgentKind
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.DisplayName,
		&i.Description,
		&i.BinaryPath,
		&i.Args,
		&i.EncryptedEnv,
		&i.Enabled,
		&i.CreatedBy,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.ToolAllowlist,
		&i.ClientType,
		&i.EncryptedMcpServers,
		&i.ModelID,
		&i.MaxCostUsd,
		&i.MaxTokens,
		&i.MaxWallClockSeconds,
		&i.KeyVersion,
	)
	return i, err
}

const listAgentKinds = `-- name: ListAgentKinds :many
SELECT id, name, display_name, description, binary_path, args, encrypted_env,
       enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers,
       model_id, max_cost_usd, max_tokens, max_wall_clock_seconds, key_version
FROM acp_agent_kinds
ORDER BY created_at DESC
`

func (q *Queries) ListAgentKinds(ctx context.Context) ([]AcpAgentKind, error) {
	rows, err := q.db.Query(ctx, listAgentKinds)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []AcpAgentKind
	for rows.Next() {
		var i AcpAgentKind
		if err := rows.Scan(
			&i.ID,
			&i.Name,
			&i.DisplayName,
			&i.Description,
			&i.BinaryPath,
			&i.Args,
			&i.EncryptedEnv,
			&i.Enabled,
			&i.CreatedBy,
			&i.CreatedAt,
			&i.UpdatedAt,
			&i.ToolAllowlist,
			&i.ClientType,
			&i.EncryptedMcpServers,
			&i.ModelID,
			&i.MaxCostUsd,
			&i.MaxTokens,
			&i.MaxWallClockSeconds,
			&i.KeyVersion,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const listEnabledAgentKinds = `-- name: ListEnabledAgentKinds :many
SELECT id, name, display_name, description, binary_path, args, encrypted_env,
       enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers,
       model_id, max_cost_usd, max_tokens, max_wall_clock_seconds, key_version
FROM acp_agent_kinds
WHERE enabled = TRUE
ORDER BY name ASC
`

func (q *Queries) ListEnabledAgentKinds(ctx context.Context) ([]AcpAgentKind, error) {
	rows, err := q.db.Query(ctx, listEnabledAgentKinds)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []AcpAgentKind
	for rows.Next() {
		var i AcpAgentKind
		if err := rows.Scan(
			&i.ID,
			&i.Name,
			&i.DisplayName,
			&i.Description,
			&i.BinaryPath,
			&i.Args,
			&i.EncryptedEnv,
			&i.Enabled,
			&i.CreatedBy,
			&i.CreatedAt,
			&i.UpdatedAt,
			&i.ToolAllowlist,
			&i.ClientType,
			&i.EncryptedMcpServers,
			&i.ModelID,
			&i.MaxCostUsd,
			&i.MaxTokens,
			&i.MaxWallClockSeconds,
			&i.KeyVersion,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const updateAgentKind = `-- name: UpdateAgentKind :one
UPDATE acp_agent_kinds
SET display_name           = $2,
    description            = $3,
    binary_path            = $4,
    args                   = $5,
    encrypted_env          = $6,
    enabled                = $7,
    tool_allowlist         = $8,
    client_type            = $9,
    encrypted_mcp_servers  = $10,
    model_id               = $11,
    max_cost_usd           = $12,
    max_tokens             = $13,
    max_wall_clock_seconds = $14,
    updated_at             = now()
WHERE id = $1
RETURNING id, name, display_name, description, binary_path, args, encrypted_env,
          enabled, created_by, created_at, updated_at, tool_allowlist, client_type, encrypted_mcp_servers,
          model_id, max_cost_usd, max_tokens, max_wall_clock_seconds, key_version
`

type UpdateAgentKindParams struct {
	ID                  pgtype.UUID    `json:"id"`
	DisplayName         string         `json:"display_name"`
	Description         string         `json:"description"`
	BinaryPath          string         `json:"binary_path"`
	Args                []string       `json:"args"`
	EncryptedEnv        []byte         `json:"encrypted_env"`
	Enabled             bool           `json:"enabled"`
	ToolAllowlist       []string       `json:"tool_allowlist"`
	ClientType          string         `json:"client_type"`
	EncryptedMcpServers []byte         `json:"encrypted_mcp_servers"`
	ModelID             pgtype.UUID    `json:"model_id"`
	MaxCostUsd          pgtype.Numeric `json:"max_cost_usd"`
	MaxTokens           *int64         `json:"max_tokens"`
	MaxWallClockSeconds *int32         `json:"max_wall_clock_seconds"`
}

func (q *Queries) UpdateAgentKind(ctx context.Context, arg UpdateAgentKindParams) (AcpAgentKind, error) {
	row := q.db.QueryRow(ctx, updateAgentKind,
		arg.ID,
		arg.DisplayName,
		arg.Description,
		arg.BinaryPath,
		arg.Args,
		arg.EncryptedEnv,
		arg.Enabled,
		arg.ToolAllowlist,
		arg.ClientType,
		arg.EncryptedMcpServers,
		arg.ModelID,
		arg.MaxCostUsd,
		arg.MaxTokens,
		arg.MaxWallClockSeconds,
	)
	var i AcpAgentKind
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.DisplayName,
		&i.Description,
		&i.BinaryPath,
		&i.Args,
		&i.EncryptedEnv,
		&i.Enabled,
		&i.CreatedBy,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.ToolAllowlist,
		&i.ClientType,
		&i.EncryptedMcpServers,
		&i.ModelID,
		&i.MaxCostUsd,
		&i.MaxTokens,
		&i.MaxWallClockSeconds,
		&i.KeyVersion,
	)
	return i, err
}
