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

package sqlc

import (
	"context"

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

const createTtsProvider = `-- name: CreateTtsProvider :one
INSERT INTO tts_providers (name, provider, config)
VALUES (
  $1,
  $2,
  $3
)
RETURNING id, name, provider, config, created_at, updated_at
`

type CreateTtsProviderParams struct {
	Name     string `json:"name"`
	Provider string `json:"provider"`
	Config   []byte `json:"config"`
}

func (q *Queries) CreateTtsProvider(ctx context.Context, arg CreateTtsProviderParams) (TtsProvider, error) {
	row := q.db.QueryRow(ctx, createTtsProvider, arg.Name, arg.Provider, arg.Config)
	var i TtsProvider
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Provider,
		&i.Config,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const deleteTtsProvider = `-- name: DeleteTtsProvider :exec
DELETE FROM tts_providers WHERE id = $1
`

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

const getTtsProviderByID = `-- name: GetTtsProviderByID :one
SELECT id, name, provider, config, created_at, updated_at FROM tts_providers WHERE id = $1
`

func (q *Queries) GetTtsProviderByID(ctx context.Context, id pgtype.UUID) (TtsProvider, error) {
	row := q.db.QueryRow(ctx, getTtsProviderByID, id)
	var i TtsProvider
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Provider,
		&i.Config,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const getTtsProviderByName = `-- name: GetTtsProviderByName :one
SELECT id, name, provider, config, created_at, updated_at FROM tts_providers WHERE name = $1
`

func (q *Queries) GetTtsProviderByName(ctx context.Context, name string) (TtsProvider, error) {
	row := q.db.QueryRow(ctx, getTtsProviderByName, name)
	var i TtsProvider
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Provider,
		&i.Config,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const listTtsProviders = `-- name: ListTtsProviders :many
SELECT id, name, provider, config, created_at, updated_at FROM tts_providers
ORDER BY created_at DESC
`

func (q *Queries) ListTtsProviders(ctx context.Context) ([]TtsProvider, error) {
	rows, err := q.db.Query(ctx, listTtsProviders)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []TtsProvider
	for rows.Next() {
		var i TtsProvider
		if err := rows.Scan(
			&i.ID,
			&i.Name,
			&i.Provider,
			&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 listTtsProvidersByProvider = `-- name: ListTtsProvidersByProvider :many
SELECT id, name, provider, config, created_at, updated_at FROM tts_providers
WHERE provider = $1
ORDER BY created_at DESC
`

func (q *Queries) ListTtsProvidersByProvider(ctx context.Context, provider string) ([]TtsProvider, error) {
	rows, err := q.db.Query(ctx, listTtsProvidersByProvider, provider)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []TtsProvider
	for rows.Next() {
		var i TtsProvider
		if err := rows.Scan(
			&i.ID,
			&i.Name,
			&i.Provider,
			&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 updateTtsProvider = `-- name: UpdateTtsProvider :one
UPDATE tts_providers
SET
  name = $1,
  provider = $2,
  config = $3,
  updated_at = now()
WHERE id = $4
RETURNING id, name, provider, config, created_at, updated_at
`

type UpdateTtsProviderParams struct {
	Name     string      `json:"name"`
	Provider string      `json:"provider"`
	Config   []byte      `json:"config"`
	ID       pgtype.UUID `json:"id"`
}

func (q *Queries) UpdateTtsProvider(ctx context.Context, arg UpdateTtsProviderParams) (TtsProvider, error) {
	row := q.db.QueryRow(ctx, updateTtsProvider,
		arg.Name,
		arg.Provider,
		arg.Config,
		arg.ID,
	)
	var i TtsProvider
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Provider,
		&i.Config,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}
