<?php

namespace App\Support\Simulation;

final class SimulationExpectations
{
    public const ANCHOR_DATE = '2026-08-01';

    /** @return array<string, array<string, mixed>> */
    public static function branches(): array
    {
        return [
            'dar' => ['name' => 'Simulation Dar es Salaam', 'code' => 'SIM-DAR', 'location' => 'Ilala', 'region' => 'Dar es Salaam', 'district' => 'Ilala', 'phone' => '0711000001', 'email' => 'sim.dar@example.test'],
            'mwanza' => ['name' => 'Simulation Mwanza', 'code' => 'SIM-MZA', 'location' => 'Nyamagana', 'region' => 'Mwanza', 'district' => 'Nyamagana', 'phone' => '0711000002', 'email' => 'sim.mwanza@example.test'],
            'arusha' => ['name' => 'Simulation Arusha', 'code' => 'SIM-ARU', 'location' => 'Arusha City', 'region' => 'Arusha', 'district' => 'Arusha', 'phone' => '0711000003', 'email' => 'sim.arusha@example.test'],
        ];
    }

    /** @return array<int, array<string, mixed>> */
    public static function staff(): array
    {
        return [
            ['username' => 'sim.dar.manager', 'name' => 'Simulation Dar Manager', 'role' => 'branch-manager', 'branch' => 'dar', 'position' => 'Branch Manager'],
            ['username' => 'sim.dar.loan', 'name' => 'Simulation Dar Loan Officer', 'role' => 'loan-officer', 'branch' => 'dar', 'position' => 'Loan Officer'],
            ['username' => 'sim.dar.cashier', 'name' => 'Simulation Dar Cashier', 'role' => 'cashier', 'branch' => 'dar', 'position' => 'Cashier'],
            ['username' => 'sim.dar.accountant', 'name' => 'Simulation Dar Accountant', 'role' => 'accountant', 'branch' => 'dar', 'position' => 'Accountant'],
            ['username' => 'sim.dar.collector', 'name' => 'Simulation Dar Debt Collector', 'role' => 'debt-collector', 'branch' => 'dar', 'position' => 'Debt Collector'],
            ['username' => 'sim.mwanza.manager', 'name' => 'Simulation Mwanza Manager', 'role' => 'branch-manager', 'branch' => 'mwanza', 'position' => 'Branch Manager'],
            ['username' => 'sim.mwanza.loan', 'name' => 'Simulation Mwanza Loan Officer', 'role' => 'loan-officer', 'branch' => 'mwanza', 'position' => 'Loan Officer'],
            ['username' => 'sim.mwanza.cashier', 'name' => 'Simulation Mwanza Cashier', 'role' => 'cashier', 'branch' => 'mwanza', 'position' => 'Cashier'],
            ['username' => 'sim.arusha.manager', 'name' => 'Simulation Arusha Manager', 'role' => 'branch-manager', 'branch' => 'arusha', 'position' => 'Branch Manager'],
            ['username' => 'sim.arusha.loan', 'name' => 'Simulation Arusha Loan Officer', 'role' => 'loan-officer', 'branch' => 'arusha', 'position' => 'Loan Officer'],
            ['username' => 'sim.inspector', 'name' => 'Simulation Loan Inspector', 'role' => 'loan-inspector', 'branch' => 'dar', 'position' => 'Loan Inspector', 'all_branches' => true],
            ['username' => 'sim.hr', 'name' => 'Simulation HR Payroll Officer', 'role' => 'hr-payroll-officer', 'branch' => 'dar', 'position' => 'HR & Payroll Officer', 'all_branches' => true],
            ['username' => 'sim.auditor', 'name' => 'Simulation Auditor', 'role' => 'auditor', 'branch' => 'dar', 'position' => 'Auditor', 'all_branches' => true],
        ];
    }

    /** @return array<string, array<int, array<string, string>>> */
    public static function accounts(): array
    {
        return [
            'dar' => [
                ['name' => 'SIM Dar Cash', 'type' => 'cash', 'opening' => '25000000.00'],
                ['name' => 'SIM Dar Bank', 'type' => 'bank', 'opening' => '75000000.00'],
                ['name' => 'SIM Dar Mobile Money', 'type' => 'mobile_money', 'opening' => '10000000.00'],
                ['name' => 'SIM Dar Petty Cash', 'type' => 'petty_cash', 'opening' => '2000000.00'],
                ['name' => 'SIM Dar Safe', 'type' => 'safe', 'opening' => '3000000.00'],
                ['name' => 'SIM Dar Collection', 'type' => 'collection', 'opening' => '1000000.00'],
                ['name' => 'SIM Dar Other', 'type' => 'other', 'opening' => '500000.00'],
            ],
            'mwanza' => [
                ['name' => 'SIM Mwanza Cash', 'type' => 'cash', 'opening' => '15000000.00'],
                ['name' => 'SIM Mwanza Bank', 'type' => 'bank', 'opening' => '40000000.00'],
                ['name' => 'SIM Mwanza Mobile Money', 'type' => 'mobile_money', 'opening' => '5000000.00'],
                ['name' => 'SIM Mwanza Petty Cash', 'type' => 'petty_cash', 'opening' => '1500000.00'],
            ],
            'arusha' => [
                ['name' => 'SIM Arusha Cash', 'type' => 'cash', 'opening' => '12000000.00'],
                ['name' => 'SIM Arusha Bank', 'type' => 'bank', 'opening' => '30000000.00'],
                ['name' => 'SIM Arusha Mobile Money', 'type' => 'mobile_money', 'opening' => '8000000.00'],
                ['name' => 'SIM Arusha Petty Cash', 'type' => 'petty_cash', 'opening' => '1000000.00'],
            ],
        ];
    }

    /** @return array<int, array<string, mixed>> */
    public static function customers(): array
    {
        return [
            ['branch' => 'dar', 'number' => 'SIM-CUS-DAR-001', 'identity_mode' => 'with_nin', 'first_name' => 'Asha', 'last_name' => 'Mrema', 'gender' => 'female', 'nin' => 'SIMNIN-DAR-001', 'phone' => '0721000001', 'occupation' => 'Shop Owner', 'monthly_income' => '1800000.00', 'status' => 'active'],
            ['branch' => 'dar', 'number' => 'SIM-CUS-DAR-002', 'identity_mode' => 'without_nin', 'first_name' => 'Juma', 'last_name' => 'Kweka', 'gender' => 'male', 'nin' => null, 'phone' => '0721000002', 'occupation' => 'Driver', 'monthly_income' => '900000.00', 'status' => 'active'],
            ['branch' => 'dar', 'number' => 'SIM-CUS-DAR-003', 'identity_mode' => 'with_nin', 'first_name' => 'Neema', 'last_name' => 'Mushi', 'gender' => 'female', 'nin' => 'SIMNIN-DAR-003', 'phone' => '0721000003', 'occupation' => 'Teacher', 'monthly_income' => '1200000.00', 'status' => 'active'],
            ['branch' => 'dar', 'number' => 'SIM-CUS-DAR-004', 'identity_mode' => 'without_nin', 'first_name' => 'Hassan', 'last_name' => 'Omari', 'gender' => 'male', 'nin' => null, 'phone' => '0721000004', 'occupation' => 'Trader', 'monthly_income' => '1500000.00', 'status' => 'inactive'],
            ['branch' => 'mwanza', 'number' => 'SIM-CUS-MZA-001', 'identity_mode' => 'with_nin', 'first_name' => 'Rehema', 'last_name' => 'John', 'gender' => 'female', 'nin' => 'SIMNIN-MZA-001', 'phone' => '0722000001', 'occupation' => 'Fish Trader', 'monthly_income' => '2100000.00', 'status' => 'active'],
            ['branch' => 'mwanza', 'number' => 'SIM-CUS-MZA-002', 'identity_mode' => 'without_nin', 'first_name' => 'Peter', 'last_name' => 'Massawe', 'gender' => 'male', 'nin' => null, 'phone' => '0722000002', 'occupation' => 'Mechanic', 'monthly_income' => '1300000.00', 'status' => 'active'],
            ['branch' => 'mwanza', 'number' => 'SIM-CUS-MZA-003', 'identity_mode' => 'with_nin', 'first_name' => 'Zawadi', 'last_name' => 'Magesa', 'gender' => 'female', 'nin' => 'SIMNIN-MZA-003', 'phone' => '0722000003', 'occupation' => 'Salon Owner', 'monthly_income' => '1100000.00', 'status' => 'active'],
            ['branch' => 'mwanza', 'number' => 'SIM-CUS-MZA-004', 'identity_mode' => 'without_nin', 'first_name' => 'Baraka', 'last_name' => 'Joseph', 'gender' => 'male', 'nin' => null, 'phone' => '0722000004', 'occupation' => 'Farmer', 'monthly_income' => '800000.00', 'status' => 'active'],
            ['branch' => 'arusha', 'number' => 'SIM-CUS-ARU-001', 'identity_mode' => 'with_nin', 'first_name' => 'Grace', 'last_name' => 'Mollel', 'gender' => 'female', 'nin' => 'SIMNIN-ARU-001', 'phone' => '0723000001', 'occupation' => 'Tour Operator', 'monthly_income' => '3000000.00', 'status' => 'active'],
            ['branch' => 'arusha', 'number' => 'SIM-CUS-ARU-002', 'identity_mode' => 'without_nin', 'first_name' => 'Daniel', 'last_name' => 'Laizer', 'gender' => 'male', 'nin' => null, 'phone' => '0723000002', 'occupation' => 'Craft Seller', 'monthly_income' => '1400000.00', 'status' => 'active'],
            ['branch' => 'arusha', 'number' => 'SIM-CUS-ARU-003', 'identity_mode' => 'with_nin', 'first_name' => 'Happy', 'last_name' => 'Shayo', 'gender' => 'female', 'nin' => 'SIMNIN-ARU-003', 'phone' => '0723000003', 'occupation' => 'Accountant', 'monthly_income' => '2200000.00', 'status' => 'active'],
            ['branch' => 'arusha', 'number' => 'SIM-CUS-ARU-004', 'identity_mode' => 'without_nin', 'first_name' => 'Musa', 'last_name' => 'Nnko', 'gender' => 'male', 'nin' => null, 'phone' => '0723000004', 'occupation' => 'Retailer', 'monthly_income' => '1000000.00', 'status' => 'active'],
        ];
    }

    /** @return array<int, array<string, mixed>> */
    public static function loanProducts(): array
    {
        return [
            ['name' => 'SIM Flat Monthly', 'minimum_amount' => '100000.00', 'maximum_amount' => '5000000.00', 'duration' => 3, 'duration_unit' => 'months', 'interest_rate' => '12.000000', 'interest_calculation_method' => 'flat', 'fixed_interest_amount' => null, 'repayment_frequency' => 'monthly', 'grace_period_days' => 0, 'late_payment_penalty_type' => 'percentage', 'late_payment_penalty_value' => '2.000000', 'processing_fee_type' => 'percentage', 'processing_fee_value' => '2.000000', 'processing_fee_payment_mode' => 'financed', 'insurance_fee_type' => 'fixed', 'insurance_fee_value' => '10000.000000', 'other_charges' => '5000.00', 'collateral_required' => false, 'guarantor_required' => false],
            ['name' => 'SIM Reducing Weekly', 'minimum_amount' => '50000.00', 'maximum_amount' => '3000000.00', 'duration' => 8, 'duration_unit' => 'weeks', 'interest_rate' => '18.000000', 'interest_calculation_method' => 'reducing_balance', 'fixed_interest_amount' => null, 'repayment_frequency' => 'weekly', 'grace_period_days' => 1, 'late_payment_penalty_type' => 'fixed', 'late_payment_penalty_value' => '5000.000000', 'processing_fee_type' => 'percentage', 'processing_fee_value' => '1.500000', 'processing_fee_payment_mode' => 'deducted', 'insurance_fee_type' => 'percentage', 'insurance_fee_value' => '1.000000', 'other_charges' => '0.00', 'collateral_required' => true, 'guarantor_required' => true],
            ['name' => 'SIM Fixed Lump Sum', 'minimum_amount' => '100000.00', 'maximum_amount' => '2000000.00', 'duration' => 30, 'duration_unit' => 'days', 'interest_rate' => '0.000000', 'interest_calculation_method' => 'fixed_amount', 'fixed_interest_amount' => '75000.00', 'repayment_frequency' => 'lump_sum', 'grace_period_days' => 2, 'late_payment_penalty_type' => 'fixed', 'late_payment_penalty_value' => '10000.000000', 'processing_fee_type' => 'fixed', 'processing_fee_value' => '15000.000000', 'processing_fee_payment_mode' => 'cash', 'insurance_fee_type' => 'fixed', 'insurance_fee_value' => '0.000000', 'other_charges' => '0.00', 'collateral_required' => false, 'guarantor_required' => true],
            ['name' => 'SIM Biweekly Secured', 'minimum_amount' => '500000.00', 'maximum_amount' => '10000000.00', 'duration' => 12, 'duration_unit' => 'weeks', 'interest_rate' => '15.000000', 'interest_calculation_method' => 'flat', 'fixed_interest_amount' => null, 'repayment_frequency' => 'biweekly', 'grace_period_days' => 0, 'late_payment_penalty_type' => 'percentage', 'late_payment_penalty_value' => '3.000000', 'processing_fee_type' => 'percentage', 'processing_fee_value' => '2.500000', 'processing_fee_payment_mode' => 'financed', 'insurance_fee_type' => 'percentage', 'insurance_fee_value' => '1.500000', 'other_charges' => '25000.00', 'collateral_required' => true, 'guarantor_required' => false],
        ];
    }

    public static function openingAccountTotal(): string
    {
        $minor = 0;
        foreach (self::accounts() as $accounts) {
            foreach ($accounts as $account) {
                $minor += (int) round(((float) $account['opening']) * 100);
            }
        }

        return number_format($minor / 100, 2, '.', '');
    }

    public static function accountCount(): int
    {
        return array_sum(array_map('count', self::accounts()));
    }
}
