using System; using System.Collections.Generic; using System.Linq; namespace BoundaryLab.Domain; public interface IDiscountPolicy { int Amount(int subtotal); } public sealed class Invoice(int subtotal) { public int Total(IDiscountPolicy policy) { if (subtotal < 0) throw new ArgumentOutOfRangeException(nameof(subtotal)); int discount = policy.Amount(subtotal); if (discount < 0 || discount > subtotal) throw new InvalidOperationException("Invalid discount"); return subtotal - discount; } }