<?php

namespace App\Support\Authorization;

final class DefaultRoleMatrix
{
    /**
     * @return array<string, array{display_name:string,description:?string,permissions:array<int,string>}>
     */
    public static function roles(): array
    {
        return [
            'super-administrator' => [
                'display_name' => 'Super Administrator',
                'description' => null,
                'permissions' => [],
            ],
            'branch-administrator' => [
                'display_name' => 'Branch Administrator (All Operations)',
                'description' => 'For a branch operated by one employee who handles all day-to-day branch operations. Access remains limited to assigned branches and excludes global system/security administration.',
                'permissions' => [
                    PermissionName::BRANCHES_VIEW->value,
                    PermissionName::BRANCHES_UPDATE->value,
                    PermissionName::USERS_VIEW->value,
                    PermissionName::USERS_CREATE->value,
                    PermissionName::USERS_UPDATE->value,
                    PermissionName::ROLES_ASSIGN->value,
                    PermissionName::ROLES_ASSIGN_SYSTEM->value,
                    PermissionName::AUDIT_VIEW->value,
                    PermissionName::REPORTS_VIEW->value,
                    PermissionName::COLLECTIONS_MANAGE->value,
                    PermissionName::LOAN_PRODUCTS_VIEW->value,
                    PermissionName::LOAN_PRODUCTS_MANAGE->value,
                    PermissionName::PAYMENTS_RECEIVE->value,
                    PermissionName::PAYROLL_MANAGE->value,
                    PermissionName::LOANS_DISBURSE->value,
                    PermissionName::CUSTOMERS_MANAGE->value,
                    PermissionName::CUSTOMERS_VIEW->value,
                    PermissionName::CUSTOMERS_CREATE->value,
                    PermissionName::CUSTOMERS_UPDATE->value,
                    PermissionName::CUSTOMERS_DOCUMENTS->value,
                    PermissionName::CUSTOMERS_GUARANTORS->value,
                    PermissionName::CUSTOMERS_WATCHLIST->value,
                    PermissionName::COLLATERAL_VIEW->value,
                    PermissionName::COLLATERAL_MANAGE->value,
                    PermissionName::COLLATERAL_CUSTODY->value,
                    PermissionName::COLLATERAL_DOCUMENTS->value,
                    PermissionName::LOANS_VIEW->value,
                    PermissionName::LOANS_CREATE->value,
                    PermissionName::LOANS_UPDATE->value,
                    PermissionName::LOANS_CONTRACT->value,
                    PermissionName::LOANS_DOCUMENTS->value,
                    PermissionName::LOANS_INSTALLMENTS_EXCUSE->value,
                    PermissionName::LOANS_APPROVE->value,
                    PermissionName::LOANS_MANAGER_APPROVE->value,
                    PermissionName::LOANS_AUTO_APPROVE->value,
                    PermissionName::LOANS_TOP_UP_VIEW->value,
                    PermissionName::LOANS_TOP_UP_CREATE->value,
                    PermissionName::LOANS_TOP_UP_EXECUTE->value,
                    PermissionName::LOANS_TOP_UP_OVERRIDE->value,
                    PermissionName::LOANS_ADJUSTMENTS_VIEW->value,
                    PermissionName::LOANS_SETTLEMENT_EXECUTE->value,
                    PermissionName::LOANS_SETTLEMENT_ADJUST->value,
                    PermissionName::LOANS_RESTRUCTURE_CREATE->value,
                    PermissionName::LOANS_RESTRUCTURE_APPROVE->value,
                    PermissionName::LOANS_WRITEOFF_VIEW->value,
                    PermissionName::LOANS_WRITEOFF_REQUEST->value,
                    PermissionName::LOANS_WRITEOFF_APPROVE->value,
                    PermissionName::LOANS_WRITEOFF_RECOVER->value,
                    PermissionName::EXPENSES_MANAGE->value,
                    PermissionName::EXPENSES_VIEW->value,
                    PermissionName::EXPENSES_CREATE->value,
                    PermissionName::EXPENSES_APPROVE->value,
                    PermissionName::EXPENSES_CATEGORIES_MANAGE->value,
                    PermissionName::EXPENSES_RECURRING_MANAGE->value,
                    PermissionName::ACCOUNTS_VIEW->value,
                    PermissionName::ACCOUNTS_MANAGE->value,
                    PermissionName::ACCOUNTS_CAPITAL->value,
                    PermissionName::ACCOUNTS_TRANSFER->value,
                    PermissionName::ACCOUNTING_VIEW->value,
                    PermissionName::FIXED_ASSETS_VIEW->value,
                    PermissionName::FIXED_ASSETS_MANAGE->value,
                    PermissionName::FIXED_ASSETS_DEPRECIATE->value,
                    PermissionName::FIXED_ASSETS_MAINTENANCE->value,
                    PermissionName::PAYMENTS_REMOTE_SUBMIT->value,
                    PermissionName::PAYMENTS_REMOTE_VERIFY->value,
                    PermissionName::NOTIFICATIONS_VIEW->value,
                    PermissionName::NOTIFICATIONS_RETRY->value,
                    PermissionName::ARREARS_VIEW->value,
                    PermissionName::ARREARS_FOLLOW_UP->value,
                    PermissionName::PAYROLL_VIEW->value,
                    PermissionName::PAYROLL_COMPENSATION_MANAGE->value,
                    PermissionName::PAYROLL_PERIODS_CREATE->value,
                    PermissionName::PAYROLL_APPROVE->value,
                    PermissionName::PAYROLL_PAY->value,
                    PermissionName::CASH_CLOSING_VIEW->value,
                    PermissionName::CASH_RECONCILIATION_PERFORM->value,
                    PermissionName::DAILY_CLOSING_PREPARE->value,
                    PermissionName::DAILY_CLOSING_CONFIRM->value,
                    PermissionName::TASKS_VIEW->value,
                    PermissionName::TASKS_MANAGE->value,
                    PermissionName::TASKS_UPDATE_STATUS->value,
                    PermissionName::CALENDAR_VIEW->value,
                    PermissionName::APPOINTMENTS_MANAGE->value,
                    PermissionName::MANAGEMENT_ALERTS_VIEW->value,
                    PermissionName::MANAGEMENT_ALERTS_MANAGE->value,
                ],
            ],
            'branch-manager' => [
                'display_name' => 'Branch Manager',
                'description' => null,
                'permissions' => [
                    PermissionName::BRANCHES_VIEW->value,
                    PermissionName::BRANCHES_UPDATE->value,
                    PermissionName::USERS_VIEW->value,
                    PermissionName::REPORTS_VIEW->value,
                    PermissionName::COLLECTIONS_MANAGE->value,
                    PermissionName::LOAN_PRODUCTS_VIEW->value,
                    PermissionName::LOAN_PRODUCTS_MANAGE->value,
                    PermissionName::ACCOUNTS_VIEW->value,
                    PermissionName::ACCOUNTS_MANAGE->value,
                    PermissionName::ACCOUNTS_TRANSFER->value,
                    PermissionName::ACCOUNTING_VIEW->value,
                    PermissionName::LOANS_DISBURSE->value,
                    PermissionName::CUSTOMERS_MANAGE->value,
                    PermissionName::CUSTOMERS_VIEW->value,
                    PermissionName::CUSTOMERS_CREATE->value,
                    PermissionName::CUSTOMERS_UPDATE->value,
                    PermissionName::CUSTOMERS_DOCUMENTS->value,
                    PermissionName::CUSTOMERS_GUARANTORS->value,
                    PermissionName::CUSTOMERS_WATCHLIST->value,
                    PermissionName::COLLATERAL_VIEW->value,
                    PermissionName::COLLATERAL_MANAGE->value,
                    PermissionName::COLLATERAL_CUSTODY->value,
                    PermissionName::COLLATERAL_DOCUMENTS->value,
                    PermissionName::LOANS_VIEW->value,
                    PermissionName::LOANS_CREATE->value,
                    PermissionName::LOANS_UPDATE->value,
                    PermissionName::LOANS_CONTRACT->value,
                    PermissionName::LOANS_DOCUMENTS->value,
                    PermissionName::LOANS_INSTALLMENTS_EXCUSE->value,
                    PermissionName::LOANS_APPROVE->value,
                    PermissionName::LOANS_MANAGER_APPROVE->value,
                    PermissionName::LOANS_AUTO_APPROVE->value,
                    PermissionName::LOANS_TOP_UP_VIEW->value,
                    PermissionName::LOANS_TOP_UP_CREATE->value,
                    PermissionName::LOANS_TOP_UP_EXECUTE->value,
                    PermissionName::LOANS_TOP_UP_OVERRIDE->value,
                    PermissionName::LOANS_ADJUSTMENTS_VIEW->value,
                    PermissionName::LOANS_SETTLEMENT_EXECUTE->value,
                    PermissionName::LOANS_SETTLEMENT_ADJUST->value,
                    PermissionName::LOANS_RESTRUCTURE_CREATE->value,
                    PermissionName::LOANS_RESTRUCTURE_APPROVE->value,
                    PermissionName::LOANS_WRITEOFF_VIEW->value,
                    PermissionName::LOANS_WRITEOFF_REQUEST->value,
                    PermissionName::LOANS_WRITEOFF_APPROVE->value,
                    PermissionName::LOANS_WRITEOFF_RECOVER->value,
                    PermissionName::EXPENSES_MANAGE->value,
                    PermissionName::EXPENSES_VIEW->value,
                    PermissionName::EXPENSES_CREATE->value,
                    PermissionName::EXPENSES_APPROVE->value,
                    PermissionName::EXPENSES_CATEGORIES_MANAGE->value,
                    PermissionName::EXPENSES_RECURRING_MANAGE->value,
                    PermissionName::FIXED_ASSETS_VIEW->value,
                    PermissionName::FIXED_ASSETS_MANAGE->value,
                    PermissionName::FIXED_ASSETS_DEPRECIATE->value,
                    PermissionName::FIXED_ASSETS_MAINTENANCE->value,
                    PermissionName::PAYMENTS_REMOTE_SUBMIT->value,
                    PermissionName::PAYMENTS_REMOTE_VERIFY->value,
                    PermissionName::NOTIFICATIONS_VIEW->value,
                    PermissionName::NOTIFICATIONS_RETRY->value,
                    PermissionName::ARREARS_VIEW->value,
                    PermissionName::ARREARS_FOLLOW_UP->value,
                    PermissionName::PAYROLL_VIEW->value,
                    PermissionName::PAYROLL_APPROVE->value,
                    PermissionName::CASH_CLOSING_VIEW->value,
                    PermissionName::DAILY_CLOSING_CONFIRM->value,
                    PermissionName::TASKS_VIEW->value,
                    PermissionName::TASKS_MANAGE->value,
                    PermissionName::TASKS_UPDATE_STATUS->value,
                    PermissionName::CALENDAR_VIEW->value,
                    PermissionName::APPOINTMENTS_MANAGE->value,
                    PermissionName::MANAGEMENT_ALERTS_VIEW->value,
                    PermissionName::MANAGEMENT_ALERTS_MANAGE->value,
                ],
            ],
            'loan-officer' => [
                'display_name' => 'Loan Officer',
                'description' => null,
                'permissions' => [
                    PermissionName::CUSTOMERS_MANAGE->value,
                    PermissionName::CUSTOMERS_VIEW->value,
                    PermissionName::CUSTOMERS_CREATE->value,
                    PermissionName::CUSTOMERS_UPDATE->value,
                    PermissionName::CUSTOMERS_DOCUMENTS->value,
                    PermissionName::CUSTOMERS_GUARANTORS->value,
                    PermissionName::CUSTOMERS_WATCHLIST->value,
                    PermissionName::LOAN_PRODUCTS_VIEW->value,
                    PermissionName::PAYMENTS_REMOTE_SUBMIT->value,
                    PermissionName::NOTIFICATIONS_VIEW->value,
                    PermissionName::ARREARS_VIEW->value,
                    PermissionName::ARREARS_FOLLOW_UP->value,
                    PermissionName::LOANS_ADJUSTMENTS_VIEW->value,
                    PermissionName::LOANS_RESTRUCTURE_CREATE->value,
                    PermissionName::LOANS_WRITEOFF_VIEW->value,
                    PermissionName::COLLATERAL_VIEW->value,
                    PermissionName::COLLATERAL_MANAGE->value,
                    PermissionName::COLLATERAL_CUSTODY->value,
                    PermissionName::COLLATERAL_DOCUMENTS->value,
                    PermissionName::LOANS_VIEW->value,
                    PermissionName::LOANS_CREATE->value,
                    PermissionName::LOANS_UPDATE->value,
                    PermissionName::LOANS_CONTRACT->value,
                    PermissionName::LOANS_DOCUMENTS->value,
                    PermissionName::LOANS_INSTALLMENTS_EXCUSE->value,
                    PermissionName::LOANS_TOP_UP_VIEW->value,
                    PermissionName::LOANS_TOP_UP_CREATE->value,
                    PermissionName::TASKS_VIEW->value,
                    PermissionName::TASKS_UPDATE_STATUS->value,
                    PermissionName::CALENDAR_VIEW->value,
                    PermissionName::APPOINTMENTS_MANAGE->value,
                ],
            ],
            'loan-inspector' => [
                'display_name' => 'Loan Inspector / Approver',
                'description' => null,
                'permissions' => [
                    PermissionName::CUSTOMERS_VIEW->value,
                    PermissionName::CUSTOMERS_DOCUMENTS->value,
                    PermissionName::CUSTOMERS_GUARANTORS->value,
                    PermissionName::LOAN_PRODUCTS_VIEW->value,
                    PermissionName::COLLATERAL_VIEW->value,
                    PermissionName::COLLATERAL_CUSTODY->value,
                    PermissionName::COLLATERAL_DOCUMENTS->value,
                    PermissionName::LOANS_VIEW->value,
                    PermissionName::LOANS_CONTRACT->value,
                    PermissionName::LOANS_DOCUMENTS->value,
                    PermissionName::LOANS_APPROVE->value,
                    PermissionName::LOANS_TOP_UP_VIEW->value,
                    PermissionName::LOANS_ADJUSTMENTS_VIEW->value,
                    PermissionName::LOANS_RESTRUCTURE_APPROVE->value,
                    PermissionName::LOANS_WRITEOFF_VIEW->value,
                    PermissionName::NOTIFICATIONS_VIEW->value,
                    PermissionName::ARREARS_VIEW->value,
                    PermissionName::TASKS_VIEW->value,
                    PermissionName::TASKS_UPDATE_STATUS->value,
                    PermissionName::CALENDAR_VIEW->value,
                ],
            ],
            'cashier' => [
                'display_name' => 'Cashier',
                'description' => null,
                'permissions' => [
                    PermissionName::PAYMENTS_RECEIVE->value,
                    PermissionName::PAYMENTS_REMOTE_SUBMIT->value,
                    PermissionName::PAYMENTS_REMOTE_VERIFY->value,
                    PermissionName::CUSTOMERS_VIEW->value,
                    PermissionName::LOANS_VIEW->value,
                    PermissionName::ACCOUNTS_VIEW->value,
                    PermissionName::LOANS_DISBURSE->value,
                    PermissionName::LOANS_TOP_UP_VIEW->value,
                    PermissionName::LOANS_TOP_UP_EXECUTE->value,
                    PermissionName::LOANS_ADJUSTMENTS_VIEW->value,
                    PermissionName::LOANS_SETTLEMENT_EXECUTE->value,
                    PermissionName::NOTIFICATIONS_VIEW->value,
                    PermissionName::LOANS_WRITEOFF_VIEW->value,
                    PermissionName::LOANS_WRITEOFF_RECOVER->value,
                    PermissionName::CASH_CLOSING_VIEW->value,
                    PermissionName::CASH_RECONCILIATION_PERFORM->value,
                    PermissionName::TASKS_VIEW->value,
                    PermissionName::TASKS_UPDATE_STATUS->value,
                    PermissionName::CALENDAR_VIEW->value,
                ],
            ],
            'accountant' => [
                'display_name' => 'Accountant',
                'description' => null,
                'permissions' => [
                    PermissionName::ACCOUNTS_VIEW->value,
                    PermissionName::ACCOUNTS_MANAGE->value,
                    PermissionName::ACCOUNTS_CAPITAL->value,
                    PermissionName::ACCOUNTS_TRANSFER->value,
                    PermissionName::ACCOUNTING_VIEW->value,
                    PermissionName::EXPENSES_MANAGE->value,
                    PermissionName::EXPENSES_VIEW->value,
                    PermissionName::EXPENSES_CREATE->value,
                    PermissionName::EXPENSES_APPROVE->value,
                    PermissionName::EXPENSES_CATEGORIES_MANAGE->value,
                    PermissionName::EXPENSES_RECURRING_MANAGE->value,
                    PermissionName::FIXED_ASSETS_VIEW->value,
                    PermissionName::FIXED_ASSETS_MANAGE->value,
                    PermissionName::FIXED_ASSETS_DEPRECIATE->value,
                    PermissionName::FIXED_ASSETS_MAINTENANCE->value,
                    PermissionName::REPORTS_VIEW->value,
                    PermissionName::CUSTOMERS_VIEW->value,
                    PermissionName::LOAN_PRODUCTS_VIEW->value,
                    PermissionName::COLLATERAL_VIEW->value,
                    PermissionName::LOANS_VIEW->value,
                    PermissionName::LOANS_DISBURSE->value,
                    PermissionName::LOANS_TOP_UP_VIEW->value,
                    PermissionName::LOANS_TOP_UP_EXECUTE->value,
                    PermissionName::LOANS_ADJUSTMENTS_VIEW->value,
                    PermissionName::LOANS_SETTLEMENT_EXECUTE->value,
                    PermissionName::PAYMENTS_REMOTE_SUBMIT->value,
                    PermissionName::PAYMENTS_REMOTE_VERIFY->value,
                    PermissionName::NOTIFICATIONS_VIEW->value,
                    PermissionName::ARREARS_VIEW->value,
                    PermissionName::LOANS_WRITEOFF_VIEW->value,
                    PermissionName::LOANS_WRITEOFF_RECOVER->value,
                    PermissionName::PAYROLL_VIEW->value,
                    PermissionName::PAYROLL_PAY->value,
                    PermissionName::CASH_CLOSING_VIEW->value,
                    PermissionName::CASH_RECONCILIATION_PERFORM->value,
                    PermissionName::DAILY_CLOSING_PREPARE->value,
                    PermissionName::TASKS_VIEW->value,
                    PermissionName::TASKS_UPDATE_STATUS->value,
                    PermissionName::CALENDAR_VIEW->value,
                    PermissionName::MANAGEMENT_ALERTS_VIEW->value,
                ],
            ],
            'debt-collector' => [
                'display_name' => 'Debt Collector',
                'description' => null,
                'permissions' => [
                    PermissionName::COLLECTIONS_MANAGE->value,
                    PermissionName::CUSTOMERS_VIEW->value,
                    PermissionName::CUSTOMERS_UPDATE->value,
                    PermissionName::CUSTOMERS_WATCHLIST->value,
                    PermissionName::COLLATERAL_VIEW->value,
                    PermissionName::COLLATERAL_CUSTODY->value,
                    PermissionName::LOANS_VIEW->value,
                    PermissionName::LOANS_ADJUSTMENTS_VIEW->value,
                    PermissionName::LOANS_RESTRUCTURE_CREATE->value,
                    PermissionName::LOANS_WRITEOFF_VIEW->value,
                    PermissionName::PAYMENTS_REMOTE_SUBMIT->value,
                    PermissionName::NOTIFICATIONS_VIEW->value,
                    PermissionName::ARREARS_VIEW->value,
                    PermissionName::ARREARS_FOLLOW_UP->value,
                    PermissionName::TASKS_VIEW->value,
                    PermissionName::TASKS_UPDATE_STATUS->value,
                    PermissionName::CALENDAR_VIEW->value,
                    PermissionName::APPOINTMENTS_MANAGE->value,
                ],
            ],
            'hr-payroll-officer' => [
                'display_name' => 'HR / Payroll Officer',
                'description' => null,
                'permissions' => [
                    PermissionName::USERS_VIEW->value,
                    PermissionName::PAYROLL_MANAGE->value,
                    PermissionName::PAYROLL_VIEW->value,
                    PermissionName::PAYROLL_COMPENSATION_MANAGE->value,
                    PermissionName::PAYROLL_PERIODS_CREATE->value,
                    PermissionName::TASKS_VIEW->value,
                    PermissionName::TASKS_UPDATE_STATUS->value,
                    PermissionName::CALENDAR_VIEW->value,
                ],
            ],
            'auditor' => [
                'display_name' => 'Auditor',
                'description' => null,
                'permissions' => [
                    PermissionName::AUDIT_VIEW->value,
                    PermissionName::REPORTS_VIEW->value,
                    PermissionName::CUSTOMERS_VIEW->value,
                    PermissionName::LOAN_PRODUCTS_VIEW->value,
                    PermissionName::COLLATERAL_VIEW->value,
                    PermissionName::LOANS_VIEW->value,
                    PermissionName::LOANS_TOP_UP_VIEW->value,
                    PermissionName::LOANS_ADJUSTMENTS_VIEW->value,
                    PermissionName::LOANS_WRITEOFF_VIEW->value,
                    PermissionName::EXPENSES_VIEW->value,
                    PermissionName::ACCOUNTS_VIEW->value,
                    PermissionName::ACCOUNTING_VIEW->value,
                    PermissionName::FIXED_ASSETS_VIEW->value,
                    PermissionName::NOTIFICATIONS_VIEW->value,
                    PermissionName::ARREARS_VIEW->value,
                    PermissionName::PAYROLL_VIEW->value,
                    PermissionName::CASH_CLOSING_VIEW->value,
                    PermissionName::CALENDAR_VIEW->value,
                    PermissionName::MANAGEMENT_ALERTS_VIEW->value,
                ],
            ],
        ];
    }

    /** @return array<int, string> */
    public static function names(): array
    {
        return array_keys(self::roles());
    }

    /** @return array<int, string> */
    public static function permissionsFor(string $roleName): array
    {
        return self::roles()[$roleName]['permissions'] ?? [];
    }
}
