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

package sqlc

import (
	"context"

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

const countMemoryProvidersByDefault = `-- name: CountMemoryProvidersByDefault :one
SELECT COUNT(*) FROM memory_providers WHERE is_default = true
`

func (q *Queries) CountMemoryProvidersByDefault(ctx context.Context) (int64, error) {
	row := q.db.QueryRow(ctx, countMemoryProvidersByDefault)
	var count int64
	err := row.Scan(&count)
	return count, err
}

const createMemoryProvider = `-- name: CreateMemoryProvider :one
INSERT INTO memory_providers (name, provider, config, is_default)
VALUES ($1, $2, $3, $4)
RETURNING id, name, provider, config, is_default, created_at, updated_at
`

type CreateMemoryProviderParams struct {
	Name      string `json:"name"`
	Provider  string `json:"provider"`
	Config    []byte `json:"config"`
	IsDefault bool   `json:"is_default"`
}

func (q *Queries) CreateMemoryProvider(ctx context.Context, arg CreateMemoryProviderParams) (MemoryProvider, error) {
	row := q.db.QueryRow(ctx, createMemoryProvider,
		arg.Name,
		arg.Provider,
		arg.Config,
		arg.IsDefault,
	)
	var i MemoryProvider
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Provider,
		&i.Config,
		&i.IsDefault,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const deleteMemoryProvider = `-- name: DeleteMemoryProvider :exec
DELETE FROM memory_providers WHERE id = $1
`

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

const getDefaultMemoryProvider = `-- name: GetDefaultMemoryProvider :one
SELECT id, name, provider, config, is_default, created_at, updated_at FROM memory_providers WHERE is_default = true LIMIT 1
`

func (q *Queries) GetDefaultMemoryProvider(ctx context.Context) (MemoryProvider, error) {
	row := q.db.QueryRow(ctx, getDefaultMemoryProvider)
	var i MemoryProvider
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Provider,
		&i.Config,
		&i.IsDefault,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const getMemoryProviderByID = `-- name: GetMemoryProviderByID :one
SELECT id, name, provider, config, is_default, created_at, updated_at FROM memory_providers WHERE id = $1
`

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

const listMemoryProviders = `-- name: ListMemoryProviders :many
SELECT id, name, provider, config, is_default, created_at, updated_at FROM memory_providers ORDER BY created_at ASC
`

func (q *Queries) ListMemoryProviders(ctx context.Context) ([]MemoryProvider, error) {
	rows, err := q.db.Query(ctx, listMemoryProviders)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []MemoryProvider
	for rows.Next() {
		var i MemoryProvider
		if err := rows.Scan(
			&i.ID,
			&i.Name,
			&i.Provider,
			&i.Config,
			&i.IsDefault,
			&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 updateMemoryProvider = `-- name: UpdateMemoryProvider :one
UPDATE memory_providers
SET name = $2,
    config = $3,
    updated_at = now()
WHERE id = $1
RETURNING id, name, provider, config, is_default, created_at, updated_at
`

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

func (q *Queries) UpdateMemoryProvider(ctx context.Context, arg UpdateMemoryProviderParams) (MemoryProvider, error) {
	row := q.db.QueryRow(ctx, updateMemoryProvider, arg.ID, arg.Name, arg.Config)
	var i MemoryProvider
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Provider,
		&i.Config,
		&i.IsDefault,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}
