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

package chatsqlc

import (
	"context"

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

const deleteLLMModel = `-- name: DeleteLLMModel :exec
DELETE FROM llm_models WHERE id = $1
`

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

const getLLMModel = `-- name: GetLLMModel :one
SELECT id, endpoint_id, model_id, display_name, capabilities, context_window, max_output_tokens, prompt_price_per_million_usd, completion_price_per_million_usd, thinking_price_per_million_usd, is_title_generator, enabled, sort_order, created_at, updated_at FROM llm_models WHERE id = $1
`

func (q *Queries) GetLLMModel(ctx context.Context, id pgtype.UUID) (LlmModel, error) {
	row := q.db.QueryRow(ctx, getLLMModel, id)
	var i LlmModel
	err := row.Scan(
		&i.ID,
		&i.EndpointID,
		&i.ModelID,
		&i.DisplayName,
		&i.Capabilities,
		&i.ContextWindow,
		&i.MaxOutputTokens,
		&i.PromptPricePerMillionUsd,
		&i.CompletionPricePerMillionUsd,
		&i.ThinkingPricePerMillionUsd,
		&i.IsTitleGenerator,
		&i.Enabled,
		&i.SortOrder,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const getTitleGeneratorModel = `-- name: GetTitleGeneratorModel :one
SELECT id, endpoint_id, model_id, display_name, capabilities, context_window, max_output_tokens, prompt_price_per_million_usd, completion_price_per_million_usd, thinking_price_per_million_usd, is_title_generator, enabled, sort_order, created_at, updated_at FROM llm_models WHERE is_title_generator = true AND enabled = true LIMIT 1
`

func (q *Queries) GetTitleGeneratorModel(ctx context.Context) (LlmModel, error) {
	row := q.db.QueryRow(ctx, getTitleGeneratorModel)
	var i LlmModel
	err := row.Scan(
		&i.ID,
		&i.EndpointID,
		&i.ModelID,
		&i.DisplayName,
		&i.Capabilities,
		&i.ContextWindow,
		&i.MaxOutputTokens,
		&i.PromptPricePerMillionUsd,
		&i.CompletionPricePerMillionUsd,
		&i.ThinkingPricePerMillionUsd,
		&i.IsTitleGenerator,
		&i.Enabled,
		&i.SortOrder,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const insertLLMModel = `-- name: InsertLLMModel :one
INSERT INTO llm_models (
    id, endpoint_id, model_id, display_name, capabilities,
    context_window, max_output_tokens,
    prompt_price_per_million_usd, completion_price_per_million_usd, thinking_price_per_million_usd,
    is_title_generator, enabled, sort_order
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)
RETURNING id, endpoint_id, model_id, display_name, capabilities, context_window, max_output_tokens, prompt_price_per_million_usd, completion_price_per_million_usd, thinking_price_per_million_usd, is_title_generator, enabled, sort_order, created_at, updated_at
`

type InsertLLMModelParams struct {
	ID                           pgtype.UUID    `json:"id"`
	EndpointID                   pgtype.UUID    `json:"endpoint_id"`
	ModelID                      string         `json:"model_id"`
	DisplayName                  string         `json:"display_name"`
	Capabilities                 []byte         `json:"capabilities"`
	ContextWindow                int32          `json:"context_window"`
	MaxOutputTokens              int32          `json:"max_output_tokens"`
	PromptPricePerMillionUsd     pgtype.Numeric `json:"prompt_price_per_million_usd"`
	CompletionPricePerMillionUsd pgtype.Numeric `json:"completion_price_per_million_usd"`
	ThinkingPricePerMillionUsd   pgtype.Numeric `json:"thinking_price_per_million_usd"`
	IsTitleGenerator             bool           `json:"is_title_generator"`
	Enabled                      bool           `json:"enabled"`
	SortOrder                    int32          `json:"sort_order"`
}

func (q *Queries) InsertLLMModel(ctx context.Context, arg InsertLLMModelParams) (LlmModel, error) {
	row := q.db.QueryRow(ctx, insertLLMModel,
		arg.ID,
		arg.EndpointID,
		arg.ModelID,
		arg.DisplayName,
		arg.Capabilities,
		arg.ContextWindow,
		arg.MaxOutputTokens,
		arg.PromptPricePerMillionUsd,
		arg.CompletionPricePerMillionUsd,
		arg.ThinkingPricePerMillionUsd,
		arg.IsTitleGenerator,
		arg.Enabled,
		arg.SortOrder,
	)
	var i LlmModel
	err := row.Scan(
		&i.ID,
		&i.EndpointID,
		&i.ModelID,
		&i.DisplayName,
		&i.Capabilities,
		&i.ContextWindow,
		&i.MaxOutputTokens,
		&i.PromptPricePerMillionUsd,
		&i.CompletionPricePerMillionUsd,
		&i.ThinkingPricePerMillionUsd,
		&i.IsTitleGenerator,
		&i.Enabled,
		&i.SortOrder,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const listLLMModels = `-- name: ListLLMModels :many
SELECT id, endpoint_id, model_id, display_name, capabilities, context_window, max_output_tokens, prompt_price_per_million_usd, completion_price_per_million_usd, thinking_price_per_million_usd, is_title_generator, enabled, sort_order, created_at, updated_at FROM llm_models
WHERE ($1::boolean = false) OR enabled = true
ORDER BY sort_order, display_name
`

func (q *Queries) ListLLMModels(ctx context.Context, dollar_1 bool) ([]LlmModel, error) {
	rows, err := q.db.Query(ctx, listLLMModels, dollar_1)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []LlmModel
	for rows.Next() {
		var i LlmModel
		if err := rows.Scan(
			&i.ID,
			&i.EndpointID,
			&i.ModelID,
			&i.DisplayName,
			&i.Capabilities,
			&i.ContextWindow,
			&i.MaxOutputTokens,
			&i.PromptPricePerMillionUsd,
			&i.CompletionPricePerMillionUsd,
			&i.ThinkingPricePerMillionUsd,
			&i.IsTitleGenerator,
			&i.Enabled,
			&i.SortOrder,
			&i.CreatedAt,
			&i.UpdatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const updateLLMModel = `-- name: UpdateLLMModel :exec
UPDATE llm_models
SET display_name = COALESCE($2, display_name),
    capabilities = COALESCE($3, capabilities),
    context_window = COALESCE($4, context_window),
    max_output_tokens = COALESCE($5, max_output_tokens),
    prompt_price_per_million_usd = COALESCE($6, prompt_price_per_million_usd),
    completion_price_per_million_usd = COALESCE($7, completion_price_per_million_usd),
    thinking_price_per_million_usd = COALESCE($8, thinking_price_per_million_usd),
    is_title_generator = COALESCE($9, is_title_generator),
    enabled = COALESCE($10, enabled),
    sort_order = COALESCE($11, sort_order),
    updated_at = NOW()
WHERE id = $1
`

type UpdateLLMModelParams struct {
	ID                           pgtype.UUID    `json:"id"`
	DisplayName                  string         `json:"display_name"`
	Capabilities                 []byte         `json:"capabilities"`
	ContextWindow                int32          `json:"context_window"`
	MaxOutputTokens              int32          `json:"max_output_tokens"`
	PromptPricePerMillionUsd     pgtype.Numeric `json:"prompt_price_per_million_usd"`
	CompletionPricePerMillionUsd pgtype.Numeric `json:"completion_price_per_million_usd"`
	ThinkingPricePerMillionUsd   pgtype.Numeric `json:"thinking_price_per_million_usd"`
	IsTitleGenerator             bool           `json:"is_title_generator"`
	Enabled                      bool           `json:"enabled"`
	SortOrder                    int32          `json:"sort_order"`
}

func (q *Queries) UpdateLLMModel(ctx context.Context, arg UpdateLLMModelParams) error {
	_, err := q.db.Exec(ctx, updateLLMModel,
		arg.ID,
		arg.DisplayName,
		arg.Capabilities,
		arg.ContextWindow,
		arg.MaxOutputTokens,
		arg.PromptPricePerMillionUsd,
		arg.CompletionPricePerMillionUsd,
		arg.ThinkingPricePerMillionUsd,
		arg.IsTitleGenerator,
		arg.Enabled,
		arg.SortOrder,
	)
	return err
}
