-- name: CreateSubscriptionItem :one
INSERT INTO core.subscription_items (subscription_id, product_id, price_id, quantity)
VALUES ($1, $2, $3, $4)
RETURNING *;

-- name: GetSubscriptionItemsBySubscriptionID :many
SELECT * FROM core.subscription_items
WHERE subscription_id = $1
ORDER BY created_at ASC;

-- name: GetSubscriptionItemByID :one
SELECT * FROM core.subscription_items
WHERE subscription_item_id = $1;

-- name: UpdateSubscriptionItemPriceProduct :one
-- Converge a core item row after an in-place Stripe price modification (paid->paid
-- switch): the Stripe item id is unchanged but it now carries a new price/product.
UPDATE core.subscription_items
SET product_id = $2, price_id = $3, quantity = $4
WHERE subscription_item_id = $1
RETURNING *;
