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

package sqlc

import (
	"context"

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

const createSearchProvider = `-- name: CreateSearchProvider :one
INSERT INTO search_providers (name, provider, config)
VALUES (
  $1,
  $2,
  $3
)
RETURNING id, name, provider, config, created_at, updated_at
`

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

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

const deleteSearchProvider = `-- name: DeleteSearchProvider :exec
DELETE FROM search_providers WHERE id = $1
`

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

const getSearchProviderByID = `-- name: GetSearchProviderByID :one
SELECT id, name, provider, config, created_at, updated_at FROM search_providers WHERE id = $1
`

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

const getSearchProviderByName = `-- name: GetSearchProviderByName :one
SELECT id, name, provider, config, created_at, updated_at FROM search_providers WHERE name = $1
`

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

const listSearchProviders = `-- name: ListSearchProviders :many
SELECT id, name, provider, config, created_at, updated_at FROM search_providers
ORDER BY created_at DESC
`

func (q *Queries) ListSearchProviders(ctx context.Context) ([]SearchProvider, error) {
	rows, err := q.db.Query(ctx, listSearchProviders)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []SearchProvider
	for rows.Next() {
		var i SearchProvider
		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 listSearchProvidersByProvider = `-- name: ListSearchProvidersByProvider :many
SELECT id, name, provider, config, created_at, updated_at FROM search_providers
WHERE provider = $1
ORDER BY created_at DESC
`

func (q *Queries) ListSearchProvidersByProvider(ctx context.Context, provider string) ([]SearchProvider, error) {
	rows, err := q.db.Query(ctx, listSearchProvidersByProvider, provider)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []SearchProvider
	for rows.Next() {
		var i SearchProvider
		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 updateSearchProvider = `-- name: UpdateSearchProvider :one
UPDATE search_providers
SET
  name = $1,
  provider = $2,
  config = $3,
  updated_at = now()
WHERE id = $4
RETURNING id, name, provider, config, created_at, updated_at
`

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

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