<?php
declare(strict_types=1);

use App\Core\Database;

return function (Database $db): void {
    $now = date('Y-m-d H:i:s');
    $effectiveFrom = '2025-09-01';
    $facilityNameAr = 'حمام السباحة الأوليمبي';

    // Lane pricing data from official pricing table
    // Format: [entity_type, time_period, price_25m, max_25m, price_50m, max_50m]
    $lanes = [
        ['schools_gov',      'morning', 500,  8, 800,  12],
        ['schools_gov',      'evening', 500,  8, 800,  12],
        ['clubs_federations','morning', 800,  8, 1000, 12],
        ['clubs_federations','evening', 800,  8, 1000, 12],
        ['other_entities',   'morning', 1000, 8, 1200, 12],
        ['other_entities',   'evening', 1000, 8, 1200, 12],
        ['foreign_entities', 'morning', 1400, 8, 1700, 12],
        ['foreign_entities', 'evening', 1400, 8, 1700, 12],
    ];

    foreach ($lanes as $row) {
        [$entityType, $timePeriod, $price25, $max25, $price50, $max50] = $row;

        // 25m lane
        $existing = $db->selectOne(
            "SELECT id FROM sa_rental_entity_pricing
             WHERE facility_type = 'pool_lane_25m' AND entity_type = ? AND time_period = ?",
            [$entityType, $timePeriod]
        );
        if (!$existing) {
            $db->insert('sa_rental_entity_pricing', [
                'facility_type'   => 'pool_lane_25m',
                'facility_name_ar'=> $facilityNameAr . ' — حارة 25 متر',
                'entity_type'     => $entityType,
                'usage_type'      => 'practice',
                'time_period'     => $timePeriod,
                'duration_minutes'=> 60,
                'price_amount'    => $price25,
                'max_players'     => $max25,
                'notes_ar'        => 'أقصى عدد ' . $max25 . ' لاعبين',
                'is_active'       => 1,
                'effective_from'  => $effectiveFrom,
                'created_at'      => $now,
                'updated_at'      => $now,
            ]);
        }

        // 50m lane
        $existing = $db->selectOne(
            "SELECT id FROM sa_rental_entity_pricing
             WHERE facility_type = 'pool_lane_50m' AND entity_type = ? AND time_period = ?",
            [$entityType, $timePeriod]
        );
        if (!$existing) {
            $db->insert('sa_rental_entity_pricing', [
                'facility_type'   => 'pool_lane_50m',
                'facility_name_ar'=> $facilityNameAr . ' — حارة 50 متر',
                'entity_type'     => $entityType,
                'usage_type'      => 'practice',
                'time_period'     => $timePeriod,
                'duration_minutes'=> 60,
                'price_amount'    => $price50,
                'max_players'     => $max50,
                'notes_ar'        => 'أقصى عدد ' . $max50 . ' لاعبين',
                'is_active'       => 1,
                'effective_from'  => $effectiveFrom,
                'created_at'      => $now,
                'updated_at'      => $now,
            ]);
        }
    }
};
