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

package chatsqlc

import (
	"context"

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

const deleteLLMEndpoint = `-- name: DeleteLLMEndpoint :exec
DELETE FROM llm_endpoints WHERE id = $1
`

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

const getLLMEndpoint = `-- name: GetLLMEndpoint :one
SELECT id, provider, display_name, base_url, api_key_encrypted, created_by, created_at, updated_at, key_version FROM llm_endpoints WHERE id = $1
`

func (q *Queries) GetLLMEndpoint(ctx context.Context, id pgtype.UUID) (LlmEndpoint, error) {
	row := q.db.QueryRow(ctx, getLLMEndpoint, id)
	var i LlmEndpoint
	err := row.Scan(
		&i.ID,
		&i.Provider,
		&i.DisplayName,
		&i.BaseUrl,
		&i.ApiKeyEncrypted,
		&i.CreatedBy,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.KeyVersion,
	)
	return i, err
}

const insertLLMEndpoint = `-- name: InsertLLMEndpoint :one
INSERT INTO llm_endpoints (id, provider, display_name, base_url, api_key_encrypted, created_by)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id, provider, display_name, base_url, api_key_encrypted, created_by, created_at, updated_at, key_version
`

type InsertLLMEndpointParams struct {
	ID              pgtype.UUID `json:"id"`
	Provider        string      `json:"provider"`
	DisplayName     string      `json:"display_name"`
	BaseUrl         string      `json:"base_url"`
	ApiKeyEncrypted []byte      `json:"api_key_encrypted"`
	CreatedBy       pgtype.UUID `json:"created_by"`
}

func (q *Queries) InsertLLMEndpoint(ctx context.Context, arg InsertLLMEndpointParams) (LlmEndpoint, error) {
	row := q.db.QueryRow(ctx, insertLLMEndpoint,
		arg.ID,
		arg.Provider,
		arg.DisplayName,
		arg.BaseUrl,
		arg.ApiKeyEncrypted,
		arg.CreatedBy,
	)
	var i LlmEndpoint
	err := row.Scan(
		&i.ID,
		&i.Provider,
		&i.DisplayName,
		&i.BaseUrl,
		&i.ApiKeyEncrypted,
		&i.CreatedBy,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.KeyVersion,
	)
	return i, err
}

const listLLMEndpoints = `-- name: ListLLMEndpoints :many
SELECT id, provider, display_name, base_url, api_key_encrypted, created_by, created_at, updated_at, key_version FROM llm_endpoints ORDER BY created_at DESC
`

func (q *Queries) ListLLMEndpoints(ctx context.Context) ([]LlmEndpoint, error) {
	rows, err := q.db.Query(ctx, listLLMEndpoints)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []LlmEndpoint
	for rows.Next() {
		var i LlmEndpoint
		if err := rows.Scan(
			&i.ID,
			&i.Provider,
			&i.DisplayName,
			&i.BaseUrl,
			&i.ApiKeyEncrypted,
			&i.CreatedBy,
			&i.CreatedAt,
			&i.UpdatedAt,
			&i.KeyVersion,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const updateLLMEndpoint = `-- name: UpdateLLMEndpoint :exec
UPDATE llm_endpoints
SET display_name = COALESCE($2, display_name),
    base_url = COALESCE($3, base_url),
    api_key_encrypted = COALESCE($4, api_key_encrypted),
    updated_at = NOW()
WHERE id = $1
`

type UpdateLLMEndpointParams struct {
	ID              pgtype.UUID `json:"id"`
	DisplayName     string      `json:"display_name"`
	BaseUrl         string      `json:"base_url"`
	ApiKeyEncrypted []byte      `json:"api_key_encrypted"`
}

func (q *Queries) UpdateLLMEndpoint(ctx context.Context, arg UpdateLLMEndpointParams) error {
	_, err := q.db.Exec(ctx, updateLLMEndpoint,
		arg.ID,
		arg.DisplayName,
		arg.BaseUrl,
		arg.ApiKeyEncrypted,
	)
	return err
}
