-- name: GetInvoiceConfigByID :one
SELECT * FROM invoice_configs
WHERE id = sqlc.arg(id);

-- name: ListInvoiceConfigs :many
SELECT * FROM invoice_configs
ORDER BY created_at DESC;

-- name: CreateInvoiceConfig :one
INSERT INTO invoice_configs (name, type, description, is_active, metadata, created_at)
VALUES (
    sqlc.arg(name),
    sqlc.arg(type),
    sqlc.arg(description),
    sqlc.arg(is_active),
    sqlc.arg(metadata),
    sqlc.arg(created_at)
)
RETURNING *;

-- name: UpdateInvoiceConfig :one
UPDATE invoice_configs
SET name = CASE WHEN sqlc.arg(name) = '' THEN name ELSE sqlc.arg(name) END,
    type = coalesce(sqlc.arg(type), type),
    description = coalesce(sqlc.arg(description), description),
    is_active = coalesce(sqlc.arg(is_active), is_active),
    metadata = coalesce(sqlc.arg(metadata), metadata),
    updated_at = sqlc.arg(updated_at)
WHERE id = sqlc.arg(id)
RETURNING *;

-- name: DeleteInvoiceConfig :execrows
DELETE FROM invoice_configs
WHERE id = sqlc.arg(id);
