*/ private const PLAY_TO_TIER = [ 'pos_2a' => 'first', 'pos_2b' => 'second', 'pos_2c' => 'third', ]; public function __construct( private readonly OddsSnapshotReader $odds, ) {} public function match(TicketItem $item, PublishedDrawResultBoard $board, Collection $combinations): array { $tier = self::PLAY_TO_TIER[$item->play_code] ?? 'first'; $suffix = $board->suffix2ForTier($tier, 0); if ($suffix === '') { return ['win_amount' => 0, 'matched_prize_tier' => null, 'match_detail' => ['reason' => 'no_suffix']]; } $snapshot = is_array($item->odds_snapshot_json) ? $item->odds_snapshot_json : null; $oddsVal = $this->odds->oddsValueForScope($snapshot, $tier); $lines = []; $total = 0; if (substr((string) $item->normalized_number, -2) === $suffix) { $bet = (int) $item->unit_bet_amount; $total = (int) floor($bet * ($oddsVal / 10_000)); $lines[] = [ 'number' => $item->original_number, 'suffix2' => $suffix, 'bet_amount' => $bet, 'odds_value' => $oddsVal, 'payout' => $total, ]; } return [ 'win_amount' => $total, 'matched_prize_tier' => $total > 0 ? $tier : null, 'match_detail' => ['lines' => $lines], ]; } }