*/ private array $itemAmounts; /** * Carry the computed application. * * @since 1.0.0 * * @param Discount $discount The discount that was applied. * @param int $total The total reduction in minor units. * @param array $itemAmounts The per-item reduction, index-aligned with the input items. */ public function __construct( Discount $discount, int $total, array $itemAmounts ) { $this->discount = $discount; $this->total = $total; $this->itemAmounts = array_values( $itemAmounts ); } /** * The discount that was applied. * * @since 1.0.0 * * @return Discount */ public function discount(): Discount { return $this->discount; } /** * The total reduction in minor units. * * @since 1.0.0 * * @return int */ public function total(): int { return $this->total; } /** * The full per-item allocation, index-aligned with the input items. * * @since 1.0.0 * * @return array The per-item reductions in minor units. */ public function itemAmounts(): array { return $this->itemAmounts; } /** * Return an item's reduction, or zero for an unknown index. * * @since 1.0.0 * * @param int $index The zero-based index of the item in the input list. * @return int The item's reduction in minor units, or 0 for an unknown index. */ public function amountForItem( int $index ): int { return $this->itemAmounts[ $index ] ?? 0; } }