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

package dbgen

import (
	"context"
)

const GetGlobalSetting = `-- name: GetGlobalSetting :one
SELECT key, value, created_at, updated_at
FROM global_settings
WHERE key = $1
`

func (q *Queries) GetGlobalSetting(ctx context.Context, key string) (GlobalSetting, error) {
	row := q.db.QueryRow(ctx, GetGlobalSetting, key)
	var i GlobalSetting
	err := row.Scan(
		&i.Key,
		&i.Value,
		&i.CreatedAt,
		&i.UpdatedAt,
	)
	return i, err
}

const GetGlobalSettings = `-- name: GetGlobalSettings :many
SELECT key, value, created_at, updated_at
FROM global_settings
`

func (q *Queries) GetGlobalSettings(ctx context.Context) ([]GlobalSetting, error) {
	rows, err := q.db.Query(ctx, GetGlobalSettings)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []GlobalSetting
	for rows.Next() {
		var i GlobalSetting
		if err := rows.Scan(
			&i.Key,
			&i.Value,
			&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 InsertGlobalSetting = `-- name: InsertGlobalSetting :exec
INSERT INTO global_settings (key, value)
VALUES ($1, $2) ON CONFLICT (key) DO
UPDATE
SET value = EXCLUDED.value
`

type InsertGlobalSettingParams struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

func (q *Queries) InsertGlobalSetting(ctx context.Context, arg InsertGlobalSettingParams) error {
	_, err := q.db.Exec(ctx, InsertGlobalSetting, arg.Key, arg.Value)
	return err
}

const UpdateGlobalSetting = `-- name: UpdateGlobalSetting :exec
UPDATE global_settings
SET value = $2,
    updated_at = CURRENT_TIMESTAMP
WHERE key = $1
`

type UpdateGlobalSettingParams struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

func (q *Queries) UpdateGlobalSetting(ctx context.Context, arg UpdateGlobalSettingParams) error {
	_, err := q.db.Exec(ctx, UpdateGlobalSetting, arg.Key, arg.Value)
	return err
}
