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

package sqlc

import (
	"context"

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

const createTtsModel = `-- name: CreateTtsModel :one
INSERT INTO tts_models (model_id, name, tts_provider_id, config)
VALUES (
  $1,
  $2,
  $3,
  $4
)
RETURNING id, model_id, name, tts_provider_id, config, created_at, updated_at
`

type CreateTtsModelParams struct {
	ModelID       string      `json:"model_id"`
	Name          pgtype.Text `json:"name"`
	TtsProviderID pgtype.UUID `json:"tts_provider_id"`
	Config        []byte      `json:"config"`
}

func (q *Queries) CreateTtsModel(ctx context.Context, arg CreateTtsModelParams) (TtsModel, error) {
	row := q.db.QueryRow(ctx, createTtsModel,
		arg.ModelID,
		arg.Name,
		arg.TtsProviderID,
		arg.Config,
	)
	var i TtsModel
	err := row.Scan(
		&i.ID,
		&i.ModelID,
		&i.Name,
		&i.TtsProviderID,
		&i.Config,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const deleteTtsModel = `-- name: DeleteTtsModel :exec
DELETE FROM tts_models WHERE id = $1
`

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

const deleteTtsModelsByProviderID = `-- name: DeleteTtsModelsByProviderID :exec
DELETE FROM tts_models WHERE tts_provider_id = $1
`

func (q *Queries) DeleteTtsModelsByProviderID(ctx context.Context, ttsProviderID pgtype.UUID) error {
	_, err := q.db.Exec(ctx, deleteTtsModelsByProviderID, ttsProviderID)
	return err
}

const getTtsModelByID = `-- name: GetTtsModelByID :one
SELECT id, model_id, name, tts_provider_id, config, created_at, updated_at FROM tts_models WHERE id = $1
`

func (q *Queries) GetTtsModelByID(ctx context.Context, id pgtype.UUID) (TtsModel, error) {
	row := q.db.QueryRow(ctx, getTtsModelByID, id)
	var i TtsModel
	err := row.Scan(
		&i.ID,
		&i.ModelID,
		&i.Name,
		&i.TtsProviderID,
		&i.Config,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const getTtsModelByProviderAndModelID = `-- name: GetTtsModelByProviderAndModelID :one
SELECT id, model_id, name, tts_provider_id, config, created_at, updated_at FROM tts_models
WHERE tts_provider_id = $1
  AND model_id = $2
LIMIT 1
`

type GetTtsModelByProviderAndModelIDParams struct {
	TtsProviderID pgtype.UUID `json:"tts_provider_id"`
	ModelID       string      `json:"model_id"`
}

func (q *Queries) GetTtsModelByProviderAndModelID(ctx context.Context, arg GetTtsModelByProviderAndModelIDParams) (TtsModel, error) {
	row := q.db.QueryRow(ctx, getTtsModelByProviderAndModelID, arg.TtsProviderID, arg.ModelID)
	var i TtsModel
	err := row.Scan(
		&i.ID,
		&i.ModelID,
		&i.Name,
		&i.TtsProviderID,
		&i.Config,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const getTtsModelWithProvider = `-- name: GetTtsModelWithProvider :one
SELECT
  tm.id, tm.model_id, tm.name, tm.tts_provider_id, tm.config, tm.created_at, tm.updated_at,
  tp.provider AS provider_type
FROM tts_models tm
JOIN tts_providers tp ON tp.id = tm.tts_provider_id
WHERE tm.id = $1
`

type GetTtsModelWithProviderRow struct {
	ID            pgtype.UUID        `json:"id"`
	ModelID       string             `json:"model_id"`
	Name          pgtype.Text        `json:"name"`
	TtsProviderID pgtype.UUID        `json:"tts_provider_id"`
	Config        []byte             `json:"config"`
	CreatedAt     pgtype.Timestamptz `json:"created_at"`
	UpdatedAt     pgtype.Timestamptz `json:"updated_at"`
	ProviderType  string             `json:"provider_type"`
}

func (q *Queries) GetTtsModelWithProvider(ctx context.Context, id pgtype.UUID) (GetTtsModelWithProviderRow, error) {
	row := q.db.QueryRow(ctx, getTtsModelWithProvider, id)
	var i GetTtsModelWithProviderRow
	err := row.Scan(
		&i.ID,
		&i.ModelID,
		&i.Name,
		&i.TtsProviderID,
		&i.Config,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.ProviderType,
	)
	return i, err
}

const listTtsModels = `-- name: ListTtsModels :many
SELECT id, model_id, name, tts_provider_id, config, created_at, updated_at FROM tts_models
ORDER BY created_at DESC
`

func (q *Queries) ListTtsModels(ctx context.Context) ([]TtsModel, error) {
	rows, err := q.db.Query(ctx, listTtsModels)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []TtsModel
	for rows.Next() {
		var i TtsModel
		if err := rows.Scan(
			&i.ID,
			&i.ModelID,
			&i.Name,
			&i.TtsProviderID,
			&i.Config,
			&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 listTtsModelsByProviderID = `-- name: ListTtsModelsByProviderID :many
SELECT id, model_id, name, tts_provider_id, config, created_at, updated_at FROM tts_models
WHERE tts_provider_id = $1
ORDER BY created_at DESC
`

func (q *Queries) ListTtsModelsByProviderID(ctx context.Context, ttsProviderID pgtype.UUID) ([]TtsModel, error) {
	rows, err := q.db.Query(ctx, listTtsModelsByProviderID, ttsProviderID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []TtsModel
	for rows.Next() {
		var i TtsModel
		if err := rows.Scan(
			&i.ID,
			&i.ModelID,
			&i.Name,
			&i.TtsProviderID,
			&i.Config,
			&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 updateTtsModel = `-- name: UpdateTtsModel :one
UPDATE tts_models
SET
  name = $1,
  config = $2,
  updated_at = now()
WHERE id = $3
RETURNING id, model_id, name, tts_provider_id, config, created_at, updated_at
`

type UpdateTtsModelParams struct {
	Name   pgtype.Text `json:"name"`
	Config []byte      `json:"config"`
	ID     pgtype.UUID `json:"id"`
}

func (q *Queries) UpdateTtsModel(ctx context.Context, arg UpdateTtsModelParams) (TtsModel, error) {
	row := q.db.QueryRow(ctx, updateTtsModel, arg.Name, arg.Config, arg.ID)
	var i TtsModel
	err := row.Scan(
		&i.ID,
		&i.ModelID,
		&i.Name,
		&i.TtsProviderID,
		&i.Config,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}
