<?php

namespace Database\Seeders;

use App\Models\OddsItem;
use App\Models\OddsVersion;
use App\Models\RiskCapItem;
use App\Support\OddsStandardScopes;
use App\Lottery\ConfigVersionStatus;
use Illuminate\Database\Seeder;

/** Applies the traditional Malaysia baseline to active and draft odds versions. */
final class TraditionalMalaysiaOddsSeeder extends Seeder
{
    public function run(): void
    {
        $codes = [
            'big', 'small', 'pos_4a', 'pos_4b', 'pos_4c', 'pos_4d', 'pos_4e', 'four_any', 'four_top', 'four_lower',
            'pos_3a', 'pos_3b', 'pos_3c', 'pos_3d', 'pos_3e', 'pos_3lower',
            'pos_2a', 'pos_2b', 'pos_2c', 'pos_2d', 'pos_2e', 'pos_2any',
        ];

        foreach (OddsVersion::query()->whereIn('status', [ConfigVersionStatus::Active->value, ConfigVersionStatus::Draft->value])->cursor() as $version) {
            foreach ($codes as $code) {
                foreach (OddsStandardScopes::presetOddsForPlay($code) as $scope => $oddsValue) {
                    OddsItem::query()
                        ->where('version_id', $version->id)
                        ->where('play_code', $code)
                        ->where('prize_scope', $scope)
                        ->update(['odds_value' => $oddsValue]);
                }
            }
        }

        // Existing default cap was calibrated for the prior 25x test multiplier.
        RiskCapItem::query()->where('cap_type', 'default')->update(['cap_amount' => 5_000_000_000_000]);
    }
}
