<?php

namespace App\Services\Settlement;

use App\Services\Settlement\Matchers\NoopSettlementMatcher;
use App\Services\Settlement\Contracts\SettlementPlayMatcher;
use App\Services\Settlement\Matchers\Pos2AbcSettlementMatcher;
use App\Services\Settlement\Matchers\Pos3AbcSettlementMatcher;
use App\Services\Settlement\Matchers\Pos2TierSettlementMatcher;
use App\Services\Settlement\Matchers\Pos3TierSettlementMatcher;
use App\Services\Settlement\Matchers\BigSpreadSettlementMatcher;
use App\Services\Settlement\Matchers\SmallSpreadSettlementMatcher;
use App\Services\Settlement\Matchers\Pos4ListTierSettlementMatcher;
use App\Services\Settlement\Matchers\StraightLikeSettlementMatcher;
use App\Services\Settlement\Matchers\Pos4ExactTierSettlementMatcher;
use App\Services\Settlement\Matchers\FirstPrizeComboSettlementMatcher;

final class SettlementMatcherRegistry
{
    public function __construct(
        private readonly StraightLikeSettlementMatcher $straight,
        private readonly BigSpreadSettlementMatcher $big,
        private readonly SmallSpreadSettlementMatcher $small,
        private readonly Pos4ExactTierSettlementMatcher $pos4Exact,
        private readonly Pos4ListTierSettlementMatcher $pos4List,
        private readonly Pos3TierSettlementMatcher $pos3Tier,
        private readonly Pos3AbcSettlementMatcher $pos3Abc,
        private readonly Pos2TierSettlementMatcher $pos2Tier,
        private readonly Pos2AbcSettlementMatcher $pos2Abc,
        private readonly FirstPrizeComboSettlementMatcher $firstPrizeCombo,
        private readonly NoopSettlementMatcher $noop,
    ) {}

    public function for(string $playCode): SettlementPlayMatcher
    {
        // half_box：PRD 一期预留；结算按已落库组合逐条取 23 档最优档，与 big/box 家族一致（§5.6.6）。
        return match ($playCode) {
            'straight', 'roll' => $this->straight,
            'big', 'ibox', 'mbox', 'box', 'half_box' => $this->big,
            'small' => $this->small,
            'pos_4a', 'pos_4b', 'pos_4c' => $this->pos4Exact,
            'pos_4d', 'pos_4e' => $this->pos4List,
            'pos_3a', 'pos_3b', 'pos_3c' => $this->pos3Tier,
            'pos_3abc' => $this->pos3Abc,
            'pos_2a', 'pos_2b', 'pos_2c' => $this->pos2Tier,
            'pos_2abc' => $this->pos2Abc,
            'head', 'tail', 'odd', 'even', 'digit_big', 'digit_small' => $this->firstPrizeCombo,
            default => $this->noop,
        };
    }
}
