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

-- name: ListAlternativeComponents :many
SELECT * FROM alternative_components;

-- name: CreateAlternativeComponent :one
INSERT INTO alternative_components (invoice_config_item_id, alternative_component_id, conversion_ratio, priority, note, metadata)
VALUES (
    sqlc.arg(invoice_config_item_id),
    sqlc.arg(alternative_component_id),
    sqlc.arg(conversion_ratio),
    sqlc.arg(priority),
    sqlc.arg(note),
    sqlc.arg(metadata)
)
RETURNING *;

-- name: UpdateAlternativeComponent :one
UPDATE alternative_components
SET invoice_config_item_id = coalesce(sqlc.arg(invoice_config_item_id), invoice_config_item_id),
    alternative_component_id = coalesce(sqlc.arg(alternative_component_id), alternative_component_id),
    conversion_ratio = coalesce(sqlc.arg(conversion_ratio), conversion_ratio),
    priority = coalesce(sqlc.arg(priority), priority),
    note = coalesce(sqlc.arg(note), note),
    metadata = coalesce(sqlc.arg(metadata), metadata)
WHERE id = sqlc.arg(id)
RETURNING *;

-- name: DeleteAlternativeComponent :execrows
DELETE FROM alternative_components
WHERE id = sqlc.arg(id);


