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

-- name: ListInvoiceConfigItems :many
SELECT * FROM invoice_config_items;

-- name: CreateInvoiceConfigItem :one
INSERT INTO invoice_config_items (invoice_config_id,component_id,required_quantity, allow_alternative,priority_order, note, metadata)
VALUES (
    sqlc.arg(invoice_config_id),
    sqlc.arg(component_id),
    sqlc.arg(required_quantity),
    sqlc.arg(allow_alternative),
    sqlc.arg(priority_order),
    sqlc.arg(note),
    sqlc.arg(metadata)
)
RETURNING *;

-- name: UpdateInvoiceConfigItem :one
UPDATE invoice_config_items
SET required_quantity = coalesce(sqlc.arg(required_quantity), required_quantity),
    allow_alternative = coalesce(sqlc.arg(allow_alternative), allow_alternative),
    priority_order = coalesce(sqlc.arg(priority_order), priority_order),
    note = coalesce(sqlc.arg(note), note),
    metadata = coalesce(sqlc.arg(metadata), metadata)
WHERE id = sqlc.arg(id)
RETURNING *;

-- name: DeleteInvoiceConfigItem :execrows
DELETE FROM invoice_config_items
WHERE id = sqlc.arg(id);
