<?php
declare(strict_types=1);

use App\Core\Database;

return function (Database $db): void {
    $now = date('Y-m-d');
    $ts = date('Y-m-d H:i:s');

    $rules = [
        // ── Age Rules ──
        ['rule_code' => 'MIN_WORKING_AGE', 'category' => 'age', 'name_ar' => 'الحد الأدنى لسن العضو العامل', 'name_en' => 'Minimum Working Member Age', 'data_type' => 'integer', 'current_value_json' => '{"value":21}', 'parameters_json' => '{"min_age":"integer"}'],
        ['rule_code' => 'CHILD_INCLUDED_MAX_AGE', 'category' => 'age', 'name_ar' => 'الحد الأقصى لسن الأبناء المشمولين', 'name_en' => 'Max Included Child Age', 'data_type' => 'integer', 'current_value_json' => '{"value":18}', 'parameters_json' => '{"max_age":"integer"}'],
        ['rule_code' => 'CHILD_INCLUDED_MAX_COUNT', 'category' => 'age', 'name_ar' => 'الحد الأقصى لعدد الأبناء المشمولين', 'name_en' => 'Max Included Children', 'data_type' => 'integer', 'current_value_json' => '{"value":3}', 'parameters_json' => '{"max_count":"integer"}'],
        ['rule_code' => 'SPOUSE_WORKING_AGE_THRESHOLD', 'category' => 'age', 'name_ar' => 'سن تصنيف الزوجة كعضو عامل', 'name_en' => 'Spouse Working Age', 'data_type' => 'integer', 'current_value_json' => '{"value":21}', 'parameters_json' => '{"threshold":"integer"}'],
        ['rule_code' => 'MALE_CHILD_FREEZE_AGE', 'category' => 'age', 'name_ar' => 'سن تجميد عضوية الذكور', 'name_en' => 'Male Freeze Age', 'data_type' => 'integer', 'current_value_json' => '{"value":25}', 'parameters_json' => '{"freeze_age":"integer"}'],
        ['rule_code' => 'TEMP_MEMBER_MAX_AGE', 'category' => 'age', 'name_ar' => 'الحد الأقصى لسن العضو المؤقت', 'name_en' => 'Max Temp Member Age', 'data_type' => 'integer', 'current_value_json' => '{"value":25}', 'parameters_json' => '{"max_age":"integer"}'],
        ['rule_code' => 'SISTER_MAX_AGE', 'category' => 'age', 'name_ar' => 'الحد الأقصى لسن الشقيقة المؤقتة', 'name_en' => 'Max Sister Age', 'data_type' => 'integer', 'current_value_json' => '{"value":25}', 'parameters_json' => '{"max_age":"integer"}'],
        ['rule_code' => 'STEPCHILD_MAX_AGE', 'category' => 'age', 'name_ar' => 'الحد الأقصى لسن ابن الزوجة/الزوج', 'name_en' => 'Max Stepchild Age', 'data_type' => 'integer', 'current_value_json' => '{"value":25}', 'parameters_json' => '{"max_age":"integer"}'],
        ['rule_code' => 'ORPHAN_MAX_AGE', 'category' => 'age', 'name_ar' => 'الحد الأقصى لسن الطفل اليتيم', 'name_en' => 'Max Orphan Age', 'data_type' => 'integer', 'current_value_json' => '{"value":25}', 'parameters_json' => '{"max_age":"integer"}'],
        ['rule_code' => 'SEASONAL_MIN_AGE', 'category' => 'age', 'name_ar' => 'الحد الأدنى لسن العضو الموسمي', 'name_en' => 'Min Seasonal Age', 'data_type' => 'integer', 'current_value_json' => '{"value":0}', 'parameters_json' => '{"min_age":"integer"}'],

        // ── Children Fee Rules ──
        ['rule_code' => 'CHILD_4TH_UNDER_18_FEE', 'category' => 'children_fee', 'name_ar' => 'رسوم الابن الرابع تحت 18', 'name_en' => '4th Child Under 18 Fee', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"5.00","base":"membership_value"}', 'parameters_json' => '{"percentage":"decimal","base":"string"}'],
        ['rule_code' => 'CHILD_FEE_AGE_18', 'category' => 'children_fee', 'name_ar' => 'رسوم ابن 18 سنة', 'name_en' => 'Child Fee Age 18', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"10.00","type":"regular"}', 'parameters_json' => '{"percentage":"decimal","type":"string"}'],
        ['rule_code' => 'CHILD_FEE_AGE_19', 'category' => 'children_fee', 'name_ar' => 'رسوم ابن 19 سنة', 'name_en' => 'Child Fee Age 19', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"15.00","type":"regular"}', 'parameters_json' => '{"percentage":"decimal","type":"string"}'],
        ['rule_code' => 'CHILD_FEE_AGE_20', 'category' => 'children_fee', 'name_ar' => 'رسوم ابن 20 سنة', 'name_en' => 'Child Fee Age 20', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"20.00","type":"regular"}', 'parameters_json' => '{"percentage":"decimal","type":"string"}'],
        ['rule_code' => 'CHILD_FEE_AGE_21', 'category' => 'children_fee', 'name_ar' => 'رسوم ابن 21 سنة (مؤقت)', 'name_en' => 'Child Fee Age 21 Temp', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"15.00","type":"temporary","until_age":25}', 'parameters_json' => '{"percentage":"decimal","type":"string","until_age":"integer"}'],
        ['rule_code' => 'CHILD_AUTO_DELETE_AGE', 'category' => 'children_fee', 'name_ar' => 'سن الحذف التلقائي', 'name_en' => 'Auto Delete Age', 'data_type' => 'integer', 'current_value_json' => '{"value":25}', 'parameters_json' => '{"age":"integer"}'],

        // ── Spouse Fee Rules ──
        ['rule_code' => 'SPOUSE_2ND_FEE', 'category' => 'spouse_fee', 'name_ar' => 'رسوم الزوجة الثانية', 'name_en' => '2nd Spouse Fee', 'data_type' => 'compound', 'current_value_json' => '{"percentage":"10.00","annual_flat":"150.00","base_date_rule":"later_of_marriage_or_membership","partial_year_rule":"round_up"}', 'parameters_json' => '{"percentage":"decimal","annual_flat":"decimal","base_date_rule":"string","partial_year_rule":"string"}'],
        ['rule_code' => 'SPOUSE_3RD_FEE', 'category' => 'spouse_fee', 'name_ar' => 'رسوم الزوجة الثالثة', 'name_en' => '3rd Spouse Fee', 'data_type' => 'compound', 'current_value_json' => '{"percentage":"20.00","annual_flat":"200.00","base_date_rule":"later_of_marriage_or_membership","partial_year_rule":"round_up"}', 'parameters_json' => '{"percentage":"decimal","annual_flat":"decimal","base_date_rule":"string","partial_year_rule":"string"}'],
        ['rule_code' => 'SPOUSE_4TH_FEE', 'category' => 'spouse_fee', 'name_ar' => 'رسوم الزوجة الرابعة', 'name_en' => '4th Spouse Fee', 'data_type' => 'compound', 'current_value_json' => '{"percentage":"30.00","annual_flat":"300.00","base_date_rule":"later_of_marriage_or_membership","partial_year_rule":"round_up"}', 'parameters_json' => '{"percentage":"decimal","annual_flat":"decimal","base_date_rule":"string","partial_year_rule":"string"}'],
        ['rule_code' => 'SPOUSE_FOREIGN_FEE', 'category' => 'spouse_fee', 'name_ar' => 'رسوم زوج/زوجة أجنبي', 'name_en' => 'Foreign Spouse Fee', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"15.00"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'SPOUSE_ACQUIRED_MEMBER_FEE', 'category' => 'spouse_fee', 'name_ar' => 'رسوم إضافة زوج لعضو مكتسب', 'name_en' => 'Acquired Member Spouse Fee', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"50.00"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'SPOUSE_BASE_MEMBER_FEE', 'category' => 'spouse_fee', 'name_ar' => 'رسوم إضافة زوج لعضو أساسي', 'name_en' => 'Base Member Spouse Fee', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"15.00"}', 'parameters_json' => '{"percentage":"decimal"}'],

        // ── Separation/Transfer Fee Rules ──
        ['rule_code' => 'SEPARATION_FEE_YEAR_1', 'category' => 'separation_fee', 'name_ar' => 'رسوم فصل السنة الأولى', 'name_en' => 'Separation Year 1', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"30.00"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'SEPARATION_FEE_YEAR_2', 'category' => 'separation_fee', 'name_ar' => 'رسوم فصل السنة الثانية', 'name_en' => 'Separation Year 2', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"20.00"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'SEPARATION_FEE_YEAR_3', 'category' => 'separation_fee', 'name_ar' => 'رسوم فصل السنة الثالثة', 'name_en' => 'Separation Year 3', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"15.00"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'SEPARATION_FEE_YEAR_4', 'category' => 'separation_fee', 'name_ar' => 'رسوم فصل السنة الرابعة', 'name_en' => 'Separation Year 4', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"10.00"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'SEPARATION_FEE_YEAR_5', 'category' => 'separation_fee', 'name_ar' => 'رسوم فصل السنة الخامسة', 'name_en' => 'Separation Year 5', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"5.00"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'SEPARATION_FEE_YEAR_6_PLUS', 'category' => 'separation_fee', 'name_ar' => 'رسوم فصل السنة السادسة وما بعد', 'name_en' => 'Separation Year 6+', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"2.50"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'WAIVER_FEE', 'category' => 'separation_fee', 'name_ar' => 'رسوم التنازل عن العضوية', 'name_en' => 'Waiver Fee', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"30.00"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'SPORTS_CONVERSION_FEE', 'category' => 'separation_fee', 'name_ar' => 'رسوم تحويل رياضي لعامل', 'name_en' => 'Sports Conversion Fee', 'data_type' => 'compound', 'current_value_json' => '{"percentage":"50.00","min_years":8}', 'parameters_json' => '{"percentage":"decimal","min_years":"integer"}'],

        // ── Divorce Rules ──
        ['rule_code' => 'DIVORCE_REQUEST_WINDOW', 'category' => 'divorce', 'name_ar' => 'مهلة تقديم طلب الفصل بعد الطلاق', 'name_en' => 'Divorce Request Window', 'data_type' => 'integer', 'current_value_json' => '{"max_years":1}', 'parameters_json' => '{"max_years":"integer"}'],
        ['rule_code' => 'DIVORCE_MIN_MEMBERSHIP_YEARS', 'category' => 'divorce', 'name_ar' => 'الحد الأدنى لسنوات العضوية', 'name_en' => 'Divorce Min Membership Years', 'data_type' => 'compound', 'current_value_json' => '{"min_years":5,"waived_if_children":true}', 'parameters_json' => '{"min_years":"integer","waived_if_children":"boolean"}'],
        ['rule_code' => 'DIVORCE_BOTH_WORKING_FEE', 'category' => 'divorce', 'name_ar' => 'رسوم طلاق - كلاهما عامل', 'name_en' => 'Divorce Both Working', 'data_type' => 'string', 'current_value_json' => '{"fee_type":"annual_subscription_only"}', 'parameters_json' => '{"fee_type":"string"}'],
        ['rule_code' => 'DIVORCE_SAME_FORM_FEE', 'category' => 'divorce', 'name_ar' => 'رسوم طلاق - استمارة واحدة', 'name_en' => 'Divorce Same Form', 'data_type' => 'compound', 'current_value_json' => '{"percentage":"10.00","treat_as":"membership_basis"}', 'parameters_json' => '{"percentage":"decimal","treat_as":"string"}'],
        ['rule_code' => 'DIVORCE_JOINED_AFTER_FEE', 'category' => 'divorce', 'name_ar' => 'رسوم طلاق - انضمام بعد العضوية', 'name_en' => 'Divorce Joined After', 'data_type' => 'compound', 'current_value_json' => '{"percentage":"50.00","treat_as":"acquired_member"}', 'parameters_json' => '{"percentage":"decimal","treat_as":"string"}'],
        ['rule_code' => 'DIVORCE_CHILD_UNDER_12', 'category' => 'divorce', 'name_ar' => 'أبناء مكتسب تحت 12', 'name_en' => 'Divorce Child Under 12', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"15.00"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'DIVORCE_CHILD_12_TO_16', 'category' => 'divorce', 'name_ar' => 'أبناء مكتسب 12-16', 'name_en' => 'Divorce Child 12-16', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"20.00"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'DIVORCE_CHILD_16_TO_18', 'category' => 'divorce', 'name_ar' => 'أبناء مكتسب 16-18', 'name_en' => 'Divorce Child 16-18', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"25.00"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'DIVORCE_CHILD_OVER_18', 'category' => 'divorce', 'name_ar' => 'أبناء مكتسب فوق 18', 'name_en' => 'Divorce Child Over 18', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"30.00"}', 'parameters_json' => '{"percentage":"decimal"}'],

        // ── Financial Rules ──
        ['rule_code' => 'INSTALLMENT_MIN_DOWN_PAYMENT', 'category' => 'financial', 'name_ar' => 'الحد الأدنى للمقدم', 'name_en' => 'Min Down Payment', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"25.00"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'INSTALLMENT_MAX_MONTHS', 'category' => 'financial', 'name_ar' => 'الحد الأقصى لشهور التقسيط', 'name_en' => 'Max Installment Months', 'data_type' => 'integer', 'current_value_json' => '{"months":30}', 'parameters_json' => '{"months":"integer"}'],
        ['rule_code' => 'INSTALLMENT_INTEREST_RATE', 'category' => 'financial', 'name_ar' => 'نسبة الفائدة السنوية', 'name_en' => 'Annual Interest Rate', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"22.00"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'INSTALLMENT_INTEREST_BASE', 'category' => 'financial', 'name_ar' => 'أساس حساب الفائدة', 'name_en' => 'Interest Base', 'data_type' => 'string', 'current_value_json' => '{"base":"remaining_balance"}', 'parameters_json' => '{"base":"string"}'],
        ['rule_code' => 'CASH_PAYMENT_WINDOW', 'category' => 'financial', 'name_ar' => 'مهلة السداد الكاش بدون فائدة', 'name_en' => 'Cash Window Days', 'data_type' => 'integer', 'current_value_json' => '{"days":30}', 'parameters_json' => '{"days":"integer"}'],
        ['rule_code' => 'FORM_NEW_MEMBERSHIP_FEE', 'category' => 'financial', 'name_ar' => 'رسوم استمارة عضوية جديدة', 'name_en' => 'New Membership Form Fee', 'data_type' => 'compound', 'current_value_json' => '{"total":"505.00","form":"500.00","stamp":"5.00"}', 'parameters_json' => '{"total":"decimal","form":"decimal","stamp":"decimal"}'],
        ['rule_code' => 'FORM_TRANSFER_FEE', 'category' => 'financial', 'name_ar' => 'رسوم استمارة تحويل/فصل', 'name_en' => 'Transfer Form Fee', 'data_type' => 'amount', 'current_value_json' => '{"amount":"570.00"}', 'parameters_json' => '{"amount":"decimal"}'],
        ['rule_code' => 'FORM_ADDITION_FEE', 'category' => 'financial', 'name_ar' => 'رسوم استمارة إضافة', 'name_en' => 'Addition Form Fee', 'data_type' => 'amount', 'current_value_json' => '{"amount":"570.00"}', 'parameters_json' => '{"amount":"decimal"}'],
        ['rule_code' => 'DEVELOPMENT_FEE', 'category' => 'financial', 'name_ar' => 'رسوم تنمية', 'name_en' => 'Development Fee', 'data_type' => 'amount', 'current_value_json' => '{"amount":"35.00"}', 'parameters_json' => '{"amount":"decimal"}'],

        // ── Penalty Rules ──
        ['rule_code' => 'LATE_SUB_FINE_YEAR_1', 'category' => 'penalty', 'name_ar' => 'غرامة تأخير سنة أولى', 'name_en' => 'Late Fine Year 1', 'data_type' => 'percentage', 'current_value_json' => '{"percentage_of_subscription":"100.00"}', 'parameters_json' => '{"percentage_of_subscription":"decimal"}'],
        ['rule_code' => 'LATE_SUB_FINE_YEAR_2', 'category' => 'penalty', 'name_ar' => 'غرامة تأخير سنة ثانية', 'name_en' => 'Late Fine Year 2', 'data_type' => 'percentage', 'current_value_json' => '{"percentage_of_subscription":"200.00"}', 'parameters_json' => '{"percentage_of_subscription":"decimal"}'],
        ['rule_code' => 'LATE_SUB_FINE_YEAR_3', 'category' => 'penalty', 'name_ar' => 'غرامة تأخير سنة ثالثة', 'name_en' => 'Late Fine Year 3', 'data_type' => 'percentage', 'current_value_json' => '{"percentage_of_subscription":"300.00"}', 'parameters_json' => '{"percentage_of_subscription":"decimal"}'],
        ['rule_code' => 'LATE_SUB_FINE_MAX_YEARS', 'category' => 'penalty', 'name_ar' => 'أقصى سنوات تراكم غرامات', 'name_en' => 'Max Fine Years', 'data_type' => 'integer', 'current_value_json' => '{"years":5}', 'parameters_json' => '{"years":"integer"}'],
        ['rule_code' => 'LATE_SUB_DROP_YEARS', 'category' => 'penalty', 'name_ar' => 'سنوات إسقاط العضوية', 'name_en' => 'Drop Years', 'data_type' => 'integer', 'current_value_json' => '{"years":5}', 'parameters_json' => '{"years":"integer"}'],
        ['rule_code' => 'VIOLATION_FINE_MIN', 'category' => 'penalty', 'name_ar' => 'الحد الأدنى للغرامة', 'name_en' => 'Min Violation Fine', 'data_type' => 'amount', 'current_value_json' => '{"amount":"200.00"}', 'parameters_json' => '{"amount":"decimal"}'],
        ['rule_code' => 'VIOLATION_FINE_MAX', 'category' => 'penalty', 'name_ar' => 'الحد الأقصى للغرامة', 'name_en' => 'Max Violation Fine', 'data_type' => 'amount', 'current_value_json' => '{"amount":"10000.00"}', 'parameters_json' => '{"amount":"decimal"}'],
        ['rule_code' => 'APPEAL_WINDOW', 'category' => 'penalty', 'name_ar' => 'مهلة التظلم', 'name_en' => 'Appeal Window', 'data_type' => 'integer', 'current_value_json' => '{"days":15}', 'parameters_json' => '{"days":"integer"}'],
        ['rule_code' => 'REVIEW_AFTER_EXPULSION', 'category' => 'penalty', 'name_ar' => 'إعادة النظر بعد الفصل', 'name_en' => 'Review After Expulsion', 'data_type' => 'integer', 'current_value_json' => '{"months":6}', 'parameters_json' => '{"months":"integer"}'],
        ['rule_code' => 'REINSTATEMENT_WINDOW', 'category' => 'penalty', 'name_ar' => 'مهلة إعادة العضوية بعد الإسقاط', 'name_en' => 'Reinstatement Window', 'data_type' => 'integer', 'current_value_json' => '{"months":12}', 'parameters_json' => '{"months":"integer"}'],

        // ── Discount Rules ──
        ['rule_code' => 'GROUP_DISCOUNT_TIER_1', 'category' => 'discount', 'name_ar' => 'خصم مجمع 5-10', 'name_en' => 'Group Discount 5-10', 'data_type' => 'compound', 'current_value_json' => '{"min":5,"max":10,"percentage":"3.00"}', 'parameters_json' => '{"min":"integer","max":"integer","percentage":"decimal"}'],
        ['rule_code' => 'GROUP_DISCOUNT_TIER_2', 'category' => 'discount', 'name_ar' => 'خصم مجمع 11-20', 'name_en' => 'Group Discount 11-20', 'data_type' => 'compound', 'current_value_json' => '{"min":11,"max":20,"percentage":"7.00"}', 'parameters_json' => '{"min":"integer","max":"integer","percentage":"decimal"}'],
        ['rule_code' => 'GROUP_DISCOUNT_TIER_3', 'category' => 'discount', 'name_ar' => 'خصم مجمع 21+', 'name_en' => 'Group Discount 21+', 'data_type' => 'compound', 'current_value_json' => '{"min":21,"max":9999,"percentage":"10.00"}', 'parameters_json' => '{"min":"integer","max":"integer","percentage":"decimal"}'],
        ['rule_code' => 'GROUP_DISCOUNT_MAX', 'category' => 'discount', 'name_ar' => 'الحد الأقصى للخصم المجمع', 'name_en' => 'Max Group Discount', 'data_type' => 'percentage', 'current_value_json' => '{"max_percentage":"10.00"}', 'parameters_json' => '{"max_percentage":"decimal"}'],
        ['rule_code' => 'CROSS_BRANCH_DISCOUNT', 'category' => 'discount', 'name_ar' => 'خصم العضوية عبر الفروع', 'name_en' => 'Cross Branch Discount', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"50.00"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'CROSS_BRANCH_BOTH_DISCOUNT', 'category' => 'discount', 'name_ar' => 'خصم عضوية فرعين للعاصمة', 'name_en' => 'Both Branches Capital Discount', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"25.00"}', 'parameters_json' => '{"percentage":"decimal"}'],

        // ── Form/Workflow Rules ──
        ['rule_code' => 'FORM_VALIDITY_DAYS', 'category' => 'workflow', 'name_ar' => 'صلاحية الاستمارة بعد الموافقة', 'name_en' => 'Form Validity Days', 'data_type' => 'integer', 'current_value_json' => '{"days":15}', 'parameters_json' => '{"days":"integer"}'],
        ['rule_code' => 'ADDRESS_CHANGE_NOTIFICATION_DAYS', 'category' => 'workflow', 'name_ar' => 'مهلة إبلاغ تغيير العنوان', 'name_en' => 'Address Change Notice', 'data_type' => 'integer', 'current_value_json' => '{"days":30}', 'parameters_json' => '{"days":"integer"}'],
        ['rule_code' => 'PASSPORT_MIN_VALIDITY_MONTHS', 'category' => 'workflow', 'name_ar' => 'الحد الأدنى لصلاحية جواز السفر', 'name_en' => 'Min Passport Validity', 'data_type' => 'integer', 'current_value_json' => '{"months":6}', 'parameters_json' => '{"months":"integer"}'],
        ['rule_code' => 'SUBSCRIPTION_COLLECTION_WINDOW', 'category' => 'workflow', 'name_ar' => 'مهلة تحصيل الاشتراك السنوي', 'name_en' => 'Collection Window', 'data_type' => 'integer', 'current_value_json' => '{"months":3}', 'parameters_json' => '{"months":"integer"}'],
        ['rule_code' => 'SUBSCRIPTION_DELAY_START', 'category' => 'workflow', 'name_ar' => 'بداية حساب التأخير', 'name_en' => 'Delay Start Month', 'data_type' => 'integer', 'current_value_json' => '{"month":10}', 'parameters_json' => '{"month":"integer"}'],
        ['rule_code' => 'MAX_ANNUAL_SUBSCRIPTION_INCREASE', 'category' => 'workflow', 'name_ar' => 'الحد الأقصى لزيادة الاشتراك السنوي', 'name_en' => 'Max Annual Increase', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"20.00"}', 'parameters_json' => '{"percentage":"decimal"}'],

        // ── Temporary Member Rules ──
        ['rule_code' => 'TEMP_MEMBER_FEE', 'category' => 'temporary', 'name_ar' => 'رسوم العضو المؤقت', 'name_en' => 'Temp Member Fee', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"10.00"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'TEMP_CHAMPIONSHIP_EXEMPT', 'category' => 'temporary', 'name_ar' => 'إعفاء بطولات جمهورية', 'name_en' => 'Championship Exempt', 'data_type' => 'boolean', 'current_value_json' => '{"exempt":true}', 'parameters_json' => '{"exempt":"boolean"}'],
        ['rule_code' => 'SEASONAL_FEE', 'category' => 'temporary', 'name_ar' => 'رسوم العضوية الموسمية', 'name_en' => 'Seasonal Fee', 'data_type' => 'percentage', 'current_value_json' => '{"percentage":"5.00"}', 'parameters_json' => '{"percentage":"decimal"}'],
        ['rule_code' => 'SEASONAL_MAX_MONTHS', 'category' => 'temporary', 'name_ar' => 'الحد الأقصى للمدة الموسمية', 'name_en' => 'Seasonal Max Months', 'data_type' => 'integer', 'current_value_json' => '{"months":6}', 'parameters_json' => '{"months":"integer"}'],

        // ── Foreign/Special Membership Rules ──
        ['rule_code' => 'FOREIGN_MEMBER_FEE_SHERATON', 'category' => 'foreign', 'name_ar' => 'رسوم أجنبي شيراتون', 'name_en' => 'Foreign Sheraton', 'data_type' => 'amount', 'current_value_json' => '{"amount_usd":"10000.00"}', 'parameters_json' => '{"amount_usd":"decimal"}'],
        ['rule_code' => 'FOREIGN_MEMBER_FEE_CAPITAL', 'category' => 'foreign', 'name_ar' => 'رسوم أجنبي العاصمة', 'name_en' => 'Foreign Capital', 'data_type' => 'amount', 'current_value_json' => '{"amount_usd":"15000.00"}', 'parameters_json' => '{"amount_usd":"decimal"}'],
        ['rule_code' => 'FOREIGN_MEMBER_INCLUDES', 'category' => 'foreign', 'name_ar' => 'عدد الأفراد المشمولين', 'name_en' => 'Foreign Includes', 'data_type' => 'compound', 'current_value_json' => '{"spouse":1,"children":3}', 'parameters_json' => '{"spouse":"integer","children":"integer"}'],
        ['rule_code' => 'HONORARY_DURATION_YEARS', 'category' => 'foreign', 'name_ar' => 'مدة العضوية الشرفية', 'name_en' => 'Honorary Duration', 'data_type' => 'integer', 'current_value_json' => '{"years":1}', 'parameters_json' => '{"years":"integer"}'],
        ['rule_code' => 'HONORARY_RENEWABLE', 'category' => 'foreign', 'name_ar' => 'قابلة للتجديد', 'name_en' => 'Honorary Renewable', 'data_type' => 'boolean', 'current_value_json' => '{"renewable":true}', 'parameters_json' => '{"renewable":"boolean"}'],
        ['rule_code' => 'SPORTS_MIN_YEARS', 'category' => 'foreign', 'name_ar' => 'الحد الأدنى لسنوات اللاعب', 'name_en' => 'Sports Min Years', 'data_type' => 'integer', 'current_value_json' => '{"years":8}', 'parameters_json' => '{"years":"integer"}'],

        // ── Death Rules ──
        ['rule_code' => 'DEATH_TRANSFER_TO', 'category' => 'death', 'name_ar' => 'نقل العضوية عند الوفاة', 'name_en' => 'Death Transfer To', 'data_type' => 'string', 'current_value_json' => '{"transfer_to":"spouse"}', 'parameters_json' => '{"transfer_to":"string"}'],
        ['rule_code' => 'DEATH_SAME_NUMBER', 'category' => 'death', 'name_ar' => 'نفس رقم العضوية', 'name_en' => 'Death Same Number', 'data_type' => 'boolean', 'current_value_json' => '{"same_number":true}', 'parameters_json' => '{"same_number":"boolean"}'],
        ['rule_code' => 'DEATH_FEE', 'category' => 'death', 'name_ar' => 'رسوم نقل الوفاة', 'name_en' => 'Death Fee Type', 'data_type' => 'string', 'current_value_json' => '{"fee_type":"form_fee_plus_annual"}', 'parameters_json' => '{"fee_type":"string"}'],
    ];

    foreach ($rules as $rule) {
        $existing = $db->selectOne("SELECT id FROM business_rules WHERE rule_code = ? AND branch_id IS NULL", [$rule['rule_code']]);
        if ($existing) {
            continue;
        }
        $db->insert('business_rules', [
            'rule_code'          => $rule['rule_code'],
            'category'           => $rule['category'],
            'name_ar'            => $rule['name_ar'],
            'name_en'            => $rule['name_en'] ?? null,
            'description_ar'     => $rule['description_ar'] ?? null,
            'data_type'          => $rule['data_type'],
            'current_value_json' => $rule['current_value_json'],
            'parameters_json'    => $rule['parameters_json'] ?? null,
            'branch_id'          => null,
            'effective_from'     => $now,
            'is_active'          => 1,
            'version'            => 1,
            'created_at'         => $ts,
            'updated_at'         => $ts,
        ]);
    }
};