How to apply fixed discounts on multiple purchases of the same product?

Good day,

I have a use case whereby my discount qualifier is being a multiple of 2. For example lets say I sell shoes on my website which go for $100 with a $10 fixed discount if I have 2, or groups of 2 in my cart. If I had 2 this would be $180, if I had 3 it would be $180+$100=$280, if I had 4 it would be $360.

How can I replicate this in functions? I cannot return a calculated amount.

I’ve tried:

discounts: [
{
targets,
value: {
fixedAmount: {
amount : input.cart.lines.filter(line => {
return (((line.quantity - (line.quantity % 2))/2) * 10).toString();
})
}
}
}
]

As far as I can understand, if the number of products is even, the discount should apply to all products. Conversely, if the number of products is odd, the discount should apply to all products except for the last one. Let me show How I did it. Let me know if this is helpful.

const pairDiscounts = lines.map((line, index) => {
    const applyDiscount = lines.length % 2 === 0 ? true : index !== lines.length - 1;

    if (applyDiscount) {
      return {
        message: "****** Customer Discount ******",
        targets: [{
          productVariant: {
            id: (line.merchandise as ProductVariant).id
          }
        }],
        value: {
          fixedAmount: {
            appliesToEachItem: true,
            amount: 50
          }
        }
      };
    } else {
      return null;
    }
  }).filter(discount => discount !== null) as Discount[];