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

package sqlc

import (
	"context"

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

const createEmailProvider = `-- name: CreateEmailProvider :one
INSERT INTO email_providers (name, provider, config)
VALUES (
  $1,
  $2,
  $3
)
RETURNING id, name, provider, config, created_at, updated_at
`

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

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

const deleteEmailProvider = `-- name: DeleteEmailProvider :exec
DELETE FROM email_providers WHERE id = $1
`

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

const getEmailProviderByID = `-- name: GetEmailProviderByID :one
SELECT id, name, provider, config, created_at, updated_at FROM email_providers WHERE id = $1
`

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

const getEmailProviderByName = `-- name: GetEmailProviderByName :one
SELECT id, name, provider, config, created_at, updated_at FROM email_providers WHERE name = $1
`

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

const listEmailProviders = `-- name: ListEmailProviders :many
SELECT id, name, provider, config, created_at, updated_at FROM email_providers
ORDER BY created_at DESC
`

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

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

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

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