Apply unique discount amounts to each cart line

Question, I have the classic situation where I want to do the 2 for $25 discounts.

I can do this in Shopify Scripts (though they time out). I can have some products (with identifying tags maybe ‘2FOR25’) that have various prices, some might be $30, some might $15, I want quantities of two discounted to $12.50.

I know the API now allows line items to be targeted for quantities, so if I have say quantity of three on line item 1 in the cart I can discount only two. That’s great.

But can I have each line item to be discounted have its own unique discount amount per line item? [I figure I can get the price of each line item, and from there figure out the discount amount]. But I don’t know if it is even possible to send each line item for a unique (different) discount amount?

Is this possible? [I cannot change the prices to be uniform before discounting.]

Please let me know, thanks!

If you want to apply different discounts to different line items, you can use DiscountApplicationStrategy.ALL and return an array of discounts as the result of your function.

https://shopify.dev/docs/api/functions/reference/product-discounts/graphql/common-objects/discountapplicationstrategy