class Permissions:
    # Dashboard & Intelligence
    DASHBOARD_VIEW = "dashboard.view"
    DASHBOARD_CUSTOMIZE = "dashboard.customize"

    # Company & Administration
    COMPANY_MANAGE = "company.manage"
    PERIOD_MANAGE = "period.manage"
    BACKUP_MANAGE = "backup.manage"
    RESTORE_EXECUTE = "restore.execute"
    INSTALL_MANAGE = "install.manage"
    UPDATE_MANAGE = "update.manage"
    SYSTEM_VIEW = "system.view"
    SYSTEM_CONFIG_MANAGE = "system.config_manage"
    CALENDAR_CONFIG_MANAGE = "calendar.config_manage"
    CALENDAR_DATASET_MANAGE = "calendar.dataset_manage"
    SUPER_ADMIN_MANAGE = "super_admin.manage"
    SYSTEM_MANAGE = "system.manage"

    # Access Control Center
    ACCESS_VIEW = "access.view"
    ACCESS_MANAGE = "access.manage"
    ROLE_MANAGE = "role.manage"
    AUTHORITY_MANAGE = "authority.manage"
    DEVICE_MANAGE = "device.manage"

    # Chart of Accounts & Ledger
    COA_READ = "coa.read"
    COA_WRITE = "coa.write"
    COA_CONTROL_OVERRIDE = "coa.control_override"
    LEDGER_READ = "ledger.read"
    PARTY_READ = "party.read"
    PARTY_WRITE = "party.write"

    # Sundry Debtors Hub (AR) & Sundry Creditors Hub (AP)
    DEBTORS_VIEW = "debtors.view"
    DEBTORS_MANAGE = "debtors.manage"
    DEBTORS_COLLECT = "debtors.collect"
    DEBTORS_APPROVE = "debtors.approve"
    DEBTORS_WRITEOFF = "debtors.writeoff"
    DEBTORS_CREDIT_OVERRIDE = "debtors.credit_override"
    DEBTORS_RA_VERIFY = "debtors.ra_verify"
    DEBTORS_RA_CERTIFY = "debtors.ra_certify"
    DEBTORS_RECONCILE = "debtors.reconcile"
    DEBTORS_CONFIG = "debtors.config"
    CREDITORS_VIEW = "creditors.view"
    CREDITORS_MANAGE = "creditors.manage"
    CREDITORS_APPROVE = "creditors.approve"
    CREDITORS_PAY_PLAN = "creditors.pay_plan"
    PARTY_RECONCILE_RUN = "party_reconcile.run"
    PARTY_STATEMENT_CONFIRM = "party_statement.confirm"

    # Vouchers (Granular Actions)
    VOUCHER_READ = "voucher.read"
    VOUCHER_CREATE = "voucher.create"
    VOUCHER_EDIT = "voucher.edit"
    VOUCHER_DELETE = "voucher.delete"
    VOUCHER_SUBMIT = "voucher.submit"
    VOUCHER_APPROVE = "voucher.approve"
    VOUCHER_REJECT = "voucher.reject"
    VOUCHER_RETURN = "voucher.return"
    VOUCHER_HOLD = "voucher.hold"
    VOUCHER_POST = "voucher.post"
    VOUCHER_REVERSE = "voucher.reverse"
    VOUCHER_PRINT = "voucher.print"
    VOUCHER_EXPORT = "voucher.export"
    VOUCHER_THEME_CUSTOMIZE = "voucher.theme_customize"
    VOUCHER_TYPE_MANAGE = "voucher.type_manage"
    VOUCHER_CLASS_MANAGE = "voucher.class_manage"
    VOUCHER_PROVISIONAL_MANAGE = "voucher.provisional_manage"
    VOUCHER_SCENARIO_VIEW = "voucher.scenario_view"
    VOUCHER_DESIGN_MANAGE = "voucher.design_manage"
    COST_CENTRE_MANAGE = "cost_centre.manage"
    COA_INLINE_CREATE = "coa.inline_create"
    OPENING_BALANCE_VIEW = "opening_balance.view"
    OPENING_BALANCE_MANAGE = "opening_balance.manage"
    OPENING_BALANCE_APPROVE = "opening_balance.approve"
    OPENING_BALANCE_POST = "opening_balance.post"
    OPENING_BALANCE_REVERSE = "opening_balance.reverse"
    OPENING_BALANCE_DIRECTION_OVERRIDE = "opening_balance.direction_override"
    OPENING_BALANCE_MIGRATION_OVERRIDE = "opening_balance.migration_override"
    OPENING_BALANCE_CARRY_FORWARD = "opening_balance.carry_forward"

    # Reports
    REPORT_READ = "report.read"
    REPORT_EXPORT = "report.export"
    REPORT_DASHBOARD_VIEW = "report.dashboard_view"
    REPORT_TB_VIEW = "report.tb_view"
    REPORT_GL_VIEW = "report.gl_view"
    REPORT_PL_VIEW = "report.pl_view"
    REPORT_BS_VIEW = "report.bs_view"
    REPORT_VOUCHER_REG_VIEW = "report.voucher_reg_view"
    REPORT_CONSTRUCTION_VIEW = "report.construction_view"
    REPORT_AGING_VIEW = "report.aging_view"
    REPORT_COST_CENTRE_VIEW = "report.cost_centre_view"
    REPORT_TAX_VIEW = "report.tax_view"
    REPORT_AUDIT_VIEW = "report.audit_view"
    REPORT_PRINT = "report.print"
    REPORT_BUILDER_MANAGE = "report.builder_manage"
    REPORT_BUILDER_SHARE = "report.builder_share"
    REPORT_SCHEDULE_MANAGE = "report.schedule_manage"
    REPORT_SENSITIVE_VIEW = "report.sensitive_view"
    REPORT_CROSS_BRANCH = "report.cross_branch"
    REPORT_CROSS_PROJECT = "report.cross_project"

    # Projects, Sites & Job Costing
    PROJECT_READ = "project.read"
    PROJECT_WRITE = "project.write"
    PROJECT_CONTRACT_MANAGE = "project.contract_manage"
    PROJECT_VARIATION_APPROVE = "project.variation_approve"
    PROJECT_DSR_APPROVE = "project.dsr_approve"
    PROJECT_BUDGET_MANAGE = "project.budget_manage"
    SITE_READ = "site.read"
    SITE_WRITE = "site.write"
    CONSTRUCTION_OPS_READ = "construction_ops.read"
    CONSTRUCTION_OPS_APPROVE = "construction_ops.approve"

    # Enterprise Operational Modules
    PROCUREMENT_READ = "procurement.read"
    PROCUREMENT_WRITE = "procurement.write"
    PROCUREMENT_APPROVE = "procurement.approve"
    PROCUREMENT_MATCH = "procurement.match"
    VENDOR_APPROVE = "vendor.approve"
    INVENTORY_READ = "inventory.read"
    INVENTORY_WRITE = "inventory.write"
    INVENTORY_APPROVE = "inventory.approve"
    INVENTORY_ADJUST = "inventory.adjust"
    INVENTORY_VALUATION = "inventory.valuation"
    HR_READ = "hr.read"
    HR_WRITE = "hr.write"
    HR_STAFF_ONBOARD = "hr.staff_onboard"
    HR_STAFF_CODE_RESET = "hr.staff_code_reset"
    HR_DEPT_TEMPLATE_MANAGE = "hr.dept_template_manage"
    HR_PROFILE_APPROVE = "hr.profile_approve"
    HR_PAYROLL_SENSITIVE = "hr.payroll_sensitive"
    TIMESHEET_APPROVE = "timesheet.approve"
    PAYROLL_CALCULATE = "payroll.calculate"
    PAYROLL_APPROVE = "payroll.approve"
    PAYROLL_POST = "payroll.post"
    HR_CONTRACT_MANAGE = "hr.contract_manage"
    HR_SALARY_STRUCTURE_MANAGE = "hr.salary_structure_manage"
    HR_SALARY_REVISION_APPROVE = "hr.salary_revision_approve"
    HR_ATTENDANCE_APPROVE = "hr.attendance_approve"
    HR_OVERTIME_APPROVE = "hr.overtime_approve"
    HR_LEAVE_APPROVE = "hr.leave_approve"
    HR_PAYROLL_PAY = "payroll.pay"
    HR_PAYSLIP_DOWNLOAD = "hr.payslip_download"
    HR_TAX_VIEW = "hr.tax_view"
    HR_ADVANCE_MANAGE = "hr.advance_manage"
    HR_FINAL_SETTLEMENT_APPROVE = "hr.final_settlement_approve"
    HR_REPORT_EXPORT = "hr.report_export"
    HR_CONFIG_MANAGE = "hr.config_manage"
    BUDGET_READ = "budget.read"
    BUDGET_WRITE = "budget.write"
    BUDGET_APPROVE = "budget.approve"
    BUDGET_TRANSFER = "budget.transfer"
    BUDGET_OVERRIDE = "budget.override"

    # Banking, Cash, Multi-Currency & Loans
    BANKING_READ = "banking.read"
    BANKING_MANAGE = "banking.manage"
    CASH_READ = "cash.read"
    CASH_MANAGE = "cash.manage"
    RECONCILIATION_MANAGE = "reconciliation.manage"
    RECONCILIATION_APPROVE = "reconciliation.approve"
    CHEQUE_READ = "cheque.read"
    CHEQUE_ISSUE = "cheque.issue"
    CHEQUE_CLEAR = "cheque.clear"
    CHEQUE_REVERSE = "cheque.reverse"
    FX_READ = "fx.read"
    FX_MANAGE = "fx.manage"
    LOAN_READ = "loan.read"
    LOAN_MANAGE = "loan.manage"
    LOAN_APPROVE = "loan.approve"
    LOAN_RATE_APPROVE = "loan.rate_approve"
    INTEREST_POST = "interest.post"
    BG_READ = "bg.read"
    BG_MANAGE = "bg.manage"
    BG_APPROVE = "bg.approve"
    BG_RELEASE = "bg.release"
    COLLATERAL_MANAGE = "collateral.manage"
    COLLATERAL_RELEASE = "collateral.release"
    TREASURY_CONFIG = "treasury.config"
    TREASURY_APPROVE = "treasury.approve"
    CASH_HANDOVER_APPROVE = "cash.handover_approve"
    RECONCILIATION_REOPEN = "reconciliation.reopen"
    FX_OVERRIDE_APPROVE = "fx.override_approve"
    CHEQUE_SIGN = "cheque.sign"

    # Audit & Sync
    AUDIT_READ = "audit.read"
    SYNC_PUSH = "sync.push"
    SYNC_PULL = "sync.pull"

    # Centralized Document, Print & Export Engine
    DOCUMENT_VIEW = "document.view"
    DOCUMENT_PREVIEW = "document.preview"
    DOCUMENT_PRINT = "document.print"
    DOCUMENT_PDF = "document.pdf"
    DOCUMENT_EXPORT_EXCEL = "document.export_excel"
    DOCUMENT_EXPORT_CSV = "document.export_csv"
    DOCUMENT_EXPORT_BULK = "document.export_bulk"
    DOCUMENT_TEMPLATE_CUSTOMIZE = "document.template_customize"
    DOCUMENT_TEMPLATE_PUBLISH = "document.template_publish"
    DOCUMENT_DELIVERY_CONFIGURE = "document.delivery_configure"
    DOCUMENT_SEND_EMAIL = "document.send_email"
    DOCUMENT_SEND_WHATSAPP = "document.send_whatsapp"
    DOCUMENT_ARCHIVE_MANAGE = "document.archive_manage"
    DOCUMENT_AUDIT_VIEW = "document.audit_view"

    # Internal Chat & Collaboration Center
    CHAT_VIEW = "chat.view"
    CHAT_SEND = "chat.send"
    CHAT_DM_CREATE = "chat.dm_create"
    CHAT_GROUP_CREATE = "chat.group_create"
    CHAT_GROUP_MANAGE = "chat.group_manage"
    CHAT_CHANNEL_CREATE = "chat.channel_create"
    CHAT_CHANNEL_MANAGE = "chat.channel_manage"
    CHAT_ATTACH = "chat.attach"
    CHAT_SHARE_LINKS = "chat.share_links"
    CHAT_PIN = "chat.pin"
    CHAT_EDIT_OWN = "chat.edit_own"
    CHAT_DELETE_OWN = "chat.delete_own"
    CHAT_MODERATE = "chat.moderate"
    CHAT_ADMIN_MANAGE = "chat.admin_manage"
    CHAT_EXPORT = "chat.export"
    CHAT_AUDIT_VIEW = "chat.audit_view"

    # Global Popup, Confirmations & Notification Center
    NOTIFICATION_VIEW = "notification.view"
    NOTIFICATION_ACTION_EXECUTE = "notification.action_execute"
    NOTIFICATION_HISTORY_EXPORT = "notification.history_export"
    NOTIFICATION_ADMIN_MANAGE = "notification.admin_manage"

    # Vehicle & Fleet Management
    VEHICLE_VIEW = "vehicle.view"
    VEHICLE_CREATE = "vehicle.create"
    VEHICLE_EDIT = "vehicle.edit"
    VEHICLE_ASSIGN_DRIVER = "vehicle.assign_driver"
    VEHICLE_TRIP_CREATE = "vehicle.trip_create"
    VEHICLE_TRIP_VERIFY = "vehicle.trip_verify"
    VEHICLE_TRIP_APPROVE = "vehicle.trip_approve"
    VEHICLE_INCOME_RECORD = "vehicle.income_record"
    VEHICLE_INCOME_APPROVE = "vehicle.income_approve"
    VEHICLE_RENTAL_MANAGE = "vehicle.rental_manage"
    VEHICLE_RENTAL_EXPENSE_CREATE = "vehicle.rental_expense_create"
    VEHICLE_RENTAL_EXPENSE_APPROVE = "vehicle.rental_expense_approve"
    VEHICLE_CASH_ENTRY = "vehicle.cash_entry"
    VEHICLE_LEDGER_VIEW = "vehicle.ledger_view"
    VEHICLE_REPORTS_EXPORT = "vehicle.reports_export"
    VEHICLE_TRIP_DISPATCH = "vehicle.trip_dispatch"
    VEHICLE_TRIP_SUBMIT = "vehicle.trip_submit"
    VEHICLE_FUEL_RECORD = "vehicle.fuel_record"
    VEHICLE_MAINT_CREATE = "vehicle.maintenance_create"
    VEHICLE_MAINT_APPROVE = "vehicle.maintenance_approve"
    VEHICLE_VOUCHER_POST = "vehicle.voucher_post"
    VEHICLE_REVERSE = "vehicle.reverse"
    VEHICLE_CONFIG_MANAGE = "vehicle.config_manage"


ALL_PERMISSIONS = [
    v for k, v in vars(Permissions).items() if not k.startswith("_") and isinstance(v, str)
]

PERMISSION_CATALOG: list[dict] = [
    {"module": "Dashboard", "code": Permissions.DASHBOARD_VIEW, "action": "View", "description": "View executive & role dashboard"},
    {"module": "Dashboard", "code": Permissions.DASHBOARD_CUSTOMIZE, "action": "Manage", "description": "Customize layout & widgets"},
    {"module": "Accounting", "code": Permissions.COA_READ, "action": "View", "description": "View Chart of Accounts"},
    {"module": "Accounting", "code": Permissions.COA_WRITE, "action": "Manage", "description": "Create/edit Chart of Accounts"},
    {"module": "Accounting", "code": Permissions.COA_CONTROL_OVERRIDE, "action": "Approve", "description": "Authorize direct control-account adjustments"},
    {"module": "Accounting", "code": Permissions.OPENING_BALANCE_VIEW, "action": "View", "description": "View opening balance entries, schedules, and reconciliation"},
    {"module": "Accounting", "code": Permissions.OPENING_BALANCE_MANAGE, "action": "Manage", "description": "Create, import, and submit opening balances"},
    {"module": "Accounting", "code": Permissions.OPENING_BALANCE_APPROVE, "action": "Approve", "description": "Approve submitted opening balance vouchers"},
    {"module": "Accounting", "code": Permissions.OPENING_BALANCE_POST, "action": "Post", "description": "Post approved opening balance vouchers to GL"},
    {"module": "Accounting", "code": Permissions.OPENING_BALANCE_REVERSE, "action": "Reverse", "description": "Reverse and correct posted opening balance vouchers"},
    {"module": "Accounting", "code": Permissions.OPENING_BALANCE_DIRECTION_OVERRIDE, "action": "Override", "description": "Override default Debit/Credit direction on opening balances"},
    {"module": "Accounting", "code": Permissions.OPENING_BALANCE_MIGRATION_OVERRIDE, "action": "Override", "description": "Authorize opening balances past conversion cutoff date"},
    {"module": "Accounting", "code": Permissions.OPENING_BALANCE_CARRY_FORWARD, "action": "Execute", "description": "Execute financial year opening balance carry-forward"},
    {"module": "Accounting", "code": Permissions.LEDGER_READ, "action": "View", "description": "View General Ledger"},
    {"module": "Accounting", "code": Permissions.PARTY_READ, "action": "View", "description": "View Customer, Supplier & Subcontractor subledgers"},
    {"module": "Accounting", "code": Permissions.PARTY_WRITE, "action": "Manage", "description": "Create/edit Parties & bill allocations"},
    {"module": "Sundry Debtors (AR)", "code": Permissions.DEBTORS_VIEW, "action": "View", "description": "View Debtors Dashboard, Customer Ledger, Aging & Statements"},
    {"module": "Sundry Debtors (AR)", "code": Permissions.DEBTORS_MANAGE, "action": "Manage", "description": "Manage Customers, Sales/RA Invoices, Receipts, Credit/Debit Notes & Advances"},
    {"module": "Sundry Debtors (AR)", "code": Permissions.DEBTORS_COLLECT, "action": "Manage", "description": "Log collection follow-ups, commitments, reminders & AR disputes"},
    {"module": "Sundry Debtors (AR)", "code": Permissions.DEBTORS_APPROVE, "action": "Approve", "description": "Approve customer onboarding, credit limits, AR notes & retention release"},
    {"module": "Sundry Debtors (AR)", "code": Permissions.DEBTORS_WRITEOFF, "action": "Approve", "description": "Authorize bad debt write-offs & control exceptions"},
    {"module": "Sundry Debtors (AR)", "code": Permissions.DEBTORS_CREDIT_OVERRIDE, "action": "Approve", "description": "Authorize customer credit limit / hold overrides"},
    {"module": "Sundry Debtors (AR)", "code": Permissions.DEBTORS_RA_VERIFY, "action": "Manage", "description": "Verify RA progress bill measurements & site engineering review"},
    {"module": "Sundry Debtors (AR)", "code": Permissions.DEBTORS_RA_CERTIFY, "action": "Approve", "description": "Authorize RA certification, final billing & AR posting"},
    {"module": "Sundry Debtors (AR)", "code": Permissions.DEBTORS_RECONCILE, "action": "Manage", "description": "Import customer statements, match exceptions & reconcile AR control"},
    {"module": "Sundry Debtors (AR)", "code": Permissions.DEBTORS_CONFIG, "action": "Manage", "description": "Configure AR policies, DSO rules, aging buckets & approval matrices"},
    {"module": "Sundry Creditors (AP)", "code": Permissions.CREDITORS_VIEW, "action": "View", "description": "View Creditors Dashboard, Supplier Ledger, Aging & Statements"},
    {"module": "Sundry Creditors (AP)", "code": Permissions.CREDITORS_MANAGE, "action": "Manage", "description": "Manage Suppliers, Subcontractors, Purchase Bills, Payments & Advances"},
    {"module": "Sundry Creditors (AP)", "code": Permissions.CREDITORS_APPROVE, "action": "Approve", "description": "Approve supplier onboarding, payment proposals, AP notes & retention release"},
    {"module": "Sundry Creditors (AP)", "code": Permissions.CREDITORS_PAY_PLAN, "action": "Manage", "description": "Prepare upcoming supplier payment schedules & liquidity plans"},
    {"module": "Control Reconciliation", "code": Permissions.PARTY_RECONCILE_RUN, "action": "Manage", "description": "Run GL-to-Subledger control reconciliations & inspect exceptions"},
    {"module": "Control Reconciliation", "code": Permissions.PARTY_STATEMENT_CONFIRM, "action": "Approve", "description": "Confirm & sign off external customer/supplier balance statements"},
    {"module": "Accounting", "code": Permissions.PERIOD_MANAGE, "action": "Manage", "description": "Lock/open fiscal periods"},
    {"module": "System Administration", "code": Permissions.CALENDAR_CONFIG_MANAGE, "action": "Manage", "description": "Configure company & branch BS/AD dual calendar settings"},
    {"module": "System Administration", "code": Permissions.CALENDAR_DATASET_MANAGE, "action": "Manage", "description": "Import, validate, approve, publish and rollback BS calendar datasets"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_READ, "action": "View", "description": "View vouchers & Day Book"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_CREATE, "action": "Create", "description": "Create draft vouchers"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_EDIT, "action": "Edit", "description": "Edit draft/rejected vouchers"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_DELETE, "action": "Delete", "description": "Delete draft vouchers"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_SUBMIT, "action": "Submit", "description": "Submit vouchers for approval"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_APPROVE, "action": "Approve", "description": "Approve submitted vouchers"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_REJECT, "action": "Reject", "description": "Reject/return submitted vouchers"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_RETURN, "action": "Return", "description": "Return voucher for revision"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_HOLD, "action": "Hold", "description": "Place voucher on hold"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_POST, "action": "Post", "description": "Post approved vouchers to ledger"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_REVERSE, "action": "Reverse", "description": "Reverse posted vouchers"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_PRINT, "action": "Print", "description": "Print vouchers"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_EXPORT, "action": "Export", "description": "Export voucher registers"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_THEME_CUSTOMIZE, "action": "Manage", "description": "Customize Voucher Theme Studio presets"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_DESIGN_MANAGE, "action": "Manage", "description": "Configure per-voucher layouts, field schemas, conditional rules & PDF designs"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_TYPE_MANAGE, "action": "Manage", "description": "Configure Tally-style Voucher Types, Subtypes & Numbering Series"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_CLASS_MANAGE, "action": "Manage", "description": "Configure automated Voucher Classes & default ledger allocations"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_PROVISIONAL_MANAGE, "action": "Manage", "description": "Create & convert Optional, Memorandum, Post-Dated & Reversing vouchers"},
    {"module": "Vouchers", "code": Permissions.VOUCHER_SCENARIO_VIEW, "action": "View", "description": "View Scenario-based provisional financial reports"},
    {"module": "Accounting", "code": Permissions.COST_CENTRE_MANAGE, "action": "Manage", "description": "Configure Cost Categories & hierarchical Cost Centres"},
    {"module": "Accounting", "code": Permissions.COA_INLINE_CREATE, "action": "Manage", "description": "Create ledgers inline (Alt+C) during voucher entry"},
    {"module": "Reports", "code": Permissions.REPORT_READ, "action": "View", "description": "View Trial Balance, P&L, Balance Sheet"},
    {"module": "Reports", "code": Permissions.REPORT_EXPORT, "action": "Export", "description": "Export financial statements"},
    {"module": "Reports", "code": Permissions.REPORT_DASHBOARD_VIEW, "action": "View", "description": "View Reports & Analytics Executive Dashboard"},
    {"module": "Reports", "code": Permissions.REPORT_TB_VIEW, "action": "View", "description": "View Trial Balance reports"},
    {"module": "Reports", "code": Permissions.REPORT_GL_VIEW, "action": "View", "description": "View General Ledger Explorer"},
    {"module": "Reports", "code": Permissions.REPORT_PL_VIEW, "action": "View", "description": "View Profit & Loss Statements"},
    {"module": "Reports", "code": Permissions.REPORT_BS_VIEW, "action": "View", "description": "View Balance Sheet Statements"},
    {"module": "Reports", "code": Permissions.REPORT_VOUCHER_REG_VIEW, "action": "View", "description": "View Enterprise Voucher Register"},
    {"module": "Reports", "code": Permissions.REPORT_CONSTRUCTION_VIEW, "action": "View", "description": "View Construction WIP, BOQ & Cost Intelligence"},
    {"module": "Reports", "code": Permissions.REPORT_AGING_VIEW, "action": "View", "description": "View Unified AP/AR Aging & Exposure"},
    {"module": "Reports", "code": Permissions.REPORT_COST_CENTRE_VIEW, "action": "View", "description": "View Cost Centre Performance & Allocations"},
    {"module": "Reports", "code": Permissions.REPORT_TAX_VIEW, "action": "View", "description": "View Tax, VAT & TDS Compliance Reports"},
    {"module": "Reports", "code": Permissions.REPORT_AUDIT_VIEW, "action": "View", "description": "View Control Reconciliations & Audit Reports"},
    {"module": "Reports", "code": Permissions.REPORT_PRINT, "action": "Print", "description": "Print financial reports & open Print Preview"},
    {"module": "Reports", "code": Permissions.REPORT_BUILDER_MANAGE, "action": "Manage", "description": "Create and run custom Report Builder definitions"},
    {"module": "Reports", "code": Permissions.REPORT_BUILDER_SHARE, "action": "Manage", "description": "Share report templates across roles/company"},
    {"module": "Reports", "code": Permissions.REPORT_SCHEDULE_MANAGE, "action": "Manage", "description": "Configure recurring scheduled reports"},
    {"module": "Reports", "code": Permissions.REPORT_SENSITIVE_VIEW, "action": "View", "description": "Access confidential & executive financial reports"},
    {"module": "Reports", "code": Permissions.REPORT_CROSS_BRANCH, "action": "View", "description": "View reports across multiple branches"},
    {"module": "Reports", "code": Permissions.REPORT_CROSS_PROJECT, "action": "View", "description": "View reports across multiple projects"},
    {"module": "Projects", "code": Permissions.PROJECT_READ, "action": "View", "description": "View projects & job costing"},
    {"module": "Projects", "code": Permissions.PROJECT_WRITE, "action": "Manage", "description": "Create/edit projects & cost codes"},
    {"module": "Projects", "code": Permissions.PROJECT_CONTRACT_MANAGE, "action": "Manage", "description": "Manage project contracts, retention & guarantees"},
    {"module": "Projects", "code": Permissions.PROJECT_VARIATION_APPROVE, "action": "Approve", "description": "Approve contract variation orders"},
    {"module": "Projects", "code": Permissions.PROJECT_DSR_APPROVE, "action": "Approve", "description": "Approve daily site reports & progress"},
    {"module": "Projects", "code": Permissions.PROJECT_BUDGET_MANAGE, "action": "Manage", "description": "Manage project cost budget ceilings"},
    {"module": "Projects", "code": Permissions.SITE_READ, "action": "View", "description": "View construction sites"},
    {"module": "Projects", "code": Permissions.SITE_WRITE, "action": "Manage", "description": "Manage construction sites"},
    {"module": "Projects", "code": Permissions.CONSTRUCTION_OPS_READ, "action": "View", "description": "View PR, PO, GRN, MB & site documents"},
    {"module": "Projects", "code": Permissions.CONSTRUCTION_OPS_APPROVE, "action": "Approve", "description": "Approve & convert operational docs to vouchers"},
    {"module": "Procurement", "code": Permissions.PROCUREMENT_READ, "action": "View", "description": "View procurement & suppliers"},
    {"module": "Procurement", "code": Permissions.PROCUREMENT_WRITE, "action": "Manage", "description": "Manage purchase requisitions, RFQs & orders"},
    {"module": "Procurement", "code": Permissions.PROCUREMENT_APPROVE, "action": "Approve", "description": "Approve requisitions, RFQs & purchase orders"},
    {"module": "Procurement", "code": Permissions.PROCUREMENT_MATCH, "action": "Approve", "description": "Perform & override 3-way invoice matching"},
    {"module": "Procurement", "code": Permissions.VENDOR_APPROVE, "action": "Approve", "description": "Approve/blacklist vendor onboarding"},
    {"module": "Inventory", "code": Permissions.INVENTORY_READ, "action": "View", "description": "View stock & material movements"},
    {"module": "Inventory", "code": Permissions.INVENTORY_WRITE, "action": "Manage", "description": "Record GRNs, issues & transfers"},
    {"module": "Inventory", "code": Permissions.INVENTORY_APPROVE, "action": "Approve", "description": "Approve GRNs, issues & site stock transfers"},
    {"module": "Inventory", "code": Permissions.INVENTORY_ADJUST, "action": "Manage", "description": "Record stock counts, write-offs & adjustments"},
    {"module": "Inventory", "code": Permissions.INVENTORY_VALUATION, "action": "View", "description": "View & run stock valuation (FIFO / WAC)"},
    {"module": "HR & Payroll", "code": Permissions.HR_READ, "action": "View", "description": "View employees & timesheets"},
    {"module": "HR & Payroll", "code": Permissions.HR_WRITE, "action": "Manage", "description": "Manage attendance, leave & timesheets"},
    {"module": "HR & Payroll", "code": Permissions.HR_STAFF_ONBOARD, "action": "Manage", "description": "Onboard staff, create linked accounts & update HR scope"},
    {"module": "HR & Payroll", "code": Permissions.HR_STAFF_CODE_RESET, "action": "Approve", "description": "Reset & manage 6-digit staff login codes"},
    {"module": "HR & Payroll", "code": Permissions.HR_DEPT_TEMPLATE_MANAGE, "action": "Manage", "description": "Configure department default roles & access templates"},
    {"module": "HR & Payroll", "code": Permissions.HR_PROFILE_APPROVE, "action": "Approve", "description": "Approve/reject protected employee profile change requests"},
    {"module": "HR & Payroll", "code": Permissions.HR_PAYROLL_SENSITIVE, "action": "View", "description": "Access confidential salary structures & payslips"},
    {"module": "HR & Payroll", "code": Permissions.TIMESHEET_APPROVE, "action": "Approve", "description": "Approve site & staff timesheets"},
    {"module": "HR & Payroll", "code": Permissions.PAYROLL_CALCULATE, "action": "Manage", "description": "Prepare & calculate payroll runs"},
    {"module": "HR & Payroll", "code": Permissions.PAYROLL_APPROVE, "action": "Approve", "description": "Approve finalized payroll runs"},
    {"module": "HR & Payroll", "code": Permissions.PAYROLL_POST, "action": "Post", "description": "Post payroll accruals to General Ledger"},
    {"module": "HR & Payroll", "code": Permissions.HR_CONTRACT_MANAGE, "action": "Manage", "description": "Manage employment contracts & lifecycle changes"},
    {"module": "HR & Payroll", "code": Permissions.HR_SALARY_STRUCTURE_MANAGE, "action": "Manage", "description": "Manage salary components, structures & formulas"},
    {"module": "HR & Payroll", "code": Permissions.HR_SALARY_REVISION_APPROVE, "action": "Approve", "description": "Approve salary revisions & increments"},
    {"module": "HR & Payroll", "code": Permissions.HR_ATTENDANCE_APPROVE, "action": "Approve", "description": "Approve daily/biometric attendance & corrections"},
    {"module": "HR & Payroll", "code": Permissions.HR_OVERTIME_APPROVE, "action": "Approve", "description": "Approve overtime claims & Labour Act cap overrides"},
    {"module": "HR & Payroll", "code": Permissions.HR_LEAVE_APPROVE, "action": "Approve", "description": "Approve leave applications, accruals & encashments"},
    {"module": "HR & Payroll", "code": Permissions.HR_PAYROLL_PAY, "action": "Approve", "description": "Confirm & disburse bank/cash salary payment batches"},
    {"module": "HR & Payroll", "code": Permissions.HR_PAYSLIP_DOWNLOAD, "action": "Export", "description": "Download and print company payslips"},
    {"module": "HR & Payroll", "code": Permissions.HR_TAX_VIEW, "action": "View", "description": "View confidential employee PAN, TDS & SSF statutory records"},
    {"module": "HR & Payroll", "code": Permissions.HR_ADVANCE_MANAGE, "action": "Manage", "description": "Manage staff advances, loans, bonuses & reimbursements"},
    {"module": "HR & Payroll", "code": Permissions.HR_FINAL_SETTLEMENT_APPROVE, "action": "Approve", "description": "Approve employee exits & final settlement vouchers"},
    {"module": "HR & Payroll", "code": Permissions.HR_REPORT_EXPORT, "action": "Export", "description": "Export HR, Payroll, Tax & SSF reports"},
    {"module": "HR & Payroll", "code": Permissions.HR_CONFIG_MANAGE, "action": "Manage", "description": "Configure HR, attendance, tax slabs & payroll GL mappings"},
    {"module": "Budgeting", "code": Permissions.BUDGET_READ, "action": "View", "description": "View company & project budgets"},
    {"module": "Budgeting", "code": Permissions.BUDGET_WRITE, "action": "Manage", "description": "Create/revise budgets & forecast scenarios"},
    {"module": "Budgeting", "code": Permissions.BUDGET_APPROVE, "action": "Approve", "description": "Approve budget baselines & revisions"},
    {"module": "Budgeting", "code": Permissions.BUDGET_TRANSFER, "action": "Manage", "description": "Transfer budgets across cost codes/sites"},
    {"module": "Budgeting", "code": Permissions.BUDGET_OVERRIDE, "action": "Approve", "description": "Authorize over-budget procurement commitments"},
    {"module": "Access Control", "code": Permissions.ACCESS_VIEW, "action": "View", "description": "View users, roles & access logs"},
    {"module": "Access Control", "code": Permissions.ACCESS_MANAGE, "action": "Manage", "description": "Manage users & data scopes"},
    {"module": "Access Control", "code": Permissions.ROLE_MANAGE, "action": "Manage", "description": "Create/clone/edit roles & permissions"},
    {"module": "Access Control", "code": Permissions.AUTHORITY_MANAGE, "action": "Manage", "description": "Configure financial approval limits"},
    {"module": "Access Control", "code": Permissions.DEVICE_MANAGE, "action": "Manage", "description": "Manage & revoke devices/sessions"},
    {"module": "Audit & Sync", "code": Permissions.AUDIT_READ, "action": "View", "description": "View immutable audit logs"},
    {"module": "Audit & Sync", "code": Permissions.SYNC_PUSH, "action": "Submit", "description": "Push offline drafts"},
    {"module": "Audit & Sync", "code": Permissions.SYNC_PULL, "action": "View", "description": "Bootstrap & pull sync feed"},
    {"module": "Administration", "code": Permissions.COMPANY_MANAGE, "action": "Manage", "description": "Company, branch & tax settings"},
    {"module": "Administration", "code": Permissions.PERIOD_MANAGE, "action": "Manage", "description": "Fiscal years, accounting periods & year-end roll-forward"},
    {"module": "Administration", "code": Permissions.SYSTEM_VIEW, "action": "View", "description": "View system health, version info & admin reports"},
    {"module": "Administration", "code": Permissions.SYSTEM_CONFIG_MANAGE, "action": "Manage", "description": "Manage global/company settings, notifications, storage & API keys"},
    {"module": "Administration", "code": Permissions.BACKUP_MANAGE, "action": "Manage", "description": "Create, verify & schedule database/file backups"},
    {"module": "Administration", "code": Permissions.RESTORE_EXECUTE, "action": "Approve", "description": "Execute database/system restore & isolated DR tests"},
    {"module": "Administration", "code": Permissions.INSTALL_MANAGE, "action": "Manage", "description": "Run system installation wizard & environment verification"},
    {"module": "Administration", "code": Permissions.UPDATE_MANAGE, "action": "Manage", "description": "Stage/apply signed updates, migrations & rollbacks"},
    {"module": "Administration", "code": Permissions.SUPER_ADMIN_MANAGE, "action": "Manage", "description": "Create/suspend Super Admins & dual-control critical governance"},
    {"module": "Administration", "code": Permissions.SYSTEM_MANAGE, "action": "Manage", "description": "Technical platform administration & maintenance mode"},
    {"module": "Treasury & Banking", "code": Permissions.BANKING_READ, "action": "View", "description": "View bank accounts & statements"},
    {"module": "Treasury & Banking", "code": Permissions.BANKING_MANAGE, "action": "Manage", "description": "Create/close bank accounts & transfers"},
    {"module": "Treasury & Banking", "code": Permissions.CASH_READ, "action": "View", "description": "View cash custody & imprest accounts"},
    {"module": "Treasury & Banking", "code": Permissions.CASH_MANAGE, "action": "Manage", "description": "Manage cash transfers & count reconciliation"},
    {"module": "Treasury & Banking", "code": Permissions.RECONCILIATION_MANAGE, "action": "Manage", "description": "Import & match bank statements"},
    {"module": "Treasury & Banking", "code": Permissions.RECONCILIATION_APPROVE, "action": "Approve", "description": "Approve & lock bank reconciliations"},
    {"module": "Treasury & Banking", "code": Permissions.CHEQUE_READ, "action": "View", "description": "View cheque register & status"},
    {"module": "Treasury & Banking", "code": Permissions.CHEQUE_ISSUE, "action": "Issue", "description": "Issue, receive, deposit & manage cheque books"},
    {"module": "Treasury & Banking", "code": Permissions.CHEQUE_CLEAR, "action": "Approve", "description": "Confirm bank cheque clearing & deposit batch settlement"},
    {"module": "Treasury & Banking", "code": Permissions.CHEQUE_REVERSE, "action": "Approve", "description": "Authorize bounced cheque reversals & stop payments"},
    {"module": "Multi-Currency & FX", "code": Permissions.FX_READ, "action": "View", "description": "View currencies & NRB exchange rates"},
    {"module": "Multi-Currency & FX", "code": Permissions.FX_MANAGE, "action": "Manage", "description": "Configure FX rates & post FX revaluations"},
    {"module": "Bank Loans & BG", "code": Permissions.LOAN_READ, "action": "View", "description": "View Nepali bank facilities, OD/CC & collateral"},
    {"module": "Bank Loans & BG", "code": Permissions.LOAN_MANAGE, "action": "Manage", "description": "Create facilities, disbursements, schedules & repayments"},
    {"module": "Bank Loans & BG", "code": Permissions.LOAN_APPROVE, "action": "Approve", "description": "Approve loan actions & NRB regulatory rules"},
    {"module": "Bank Loans & BG", "code": Permissions.LOAN_RATE_APPROVE, "action": "Approve", "description": "Approve effective-dated interest rate revisions & overrides"},
    {"module": "Bank Loans & BG", "code": Permissions.INTEREST_POST, "action": "Approve", "description": "Post calculated loan & OD/CC interest accruals to GL"},
    {"module": "Bank Loans & BG", "code": Permissions.BG_READ, "action": "View", "description": "View bank guarantees & contingent exposure"},
    {"module": "Bank Loans & BG", "code": Permissions.BG_MANAGE, "action": "Manage", "description": "Create/amend/extend bank guarantees & upload scans"},
    {"module": "Bank Loans & BG", "code": Permissions.BG_APPROVE, "action": "Approve", "description": "Approve bank guarantees & invocations"},
    {"module": "Bank Loans & BG", "code": Permissions.BG_RELEASE, "action": "Approve", "description": "Verify discharge proof & formally release bank guarantees + margin"},
    {"module": "Bank Loans & BG", "code": Permissions.COLLATERAL_MANAGE, "action": "Manage", "description": "Manage collateral valuations & shared facility allocations"},
    {"module": "Bank Loans & BG", "code": Permissions.COLLATERAL_RELEASE, "action": "Approve", "description": "Approve formal discharge and release of collateral security"},
    {"module": "Treasury & Banking", "code": Permissions.TREASURY_CONFIG, "action": "Manage", "description": "Configure treasury policies, NRB BFIs, FX rules & reconciliation templates"},
    {"module": "Treasury & Banking", "code": Permissions.TREASURY_APPROVE, "action": "Approve", "description": "Approve treasury master edits, imprest settlements & OD excess exceptions"},
    {"module": "Treasury & Banking", "code": Permissions.CASH_HANDOVER_APPROVE, "action": "Approve", "description": "Approve physical cash handovers and shortage/excess adjustments"},
    {"module": "Treasury & Banking", "code": Permissions.RECONCILIATION_REOPEN, "action": "Approve", "description": "Reopen locked bank reconciliation periods with audit reason"},
    {"module": "Multi-Currency & FX", "code": Permissions.FX_OVERRIDE_APPROVE, "action": "Approve", "description": "Approve manual FX rate overrides above reference tolerance"},
    {"module": "Treasury & Banking", "code": Permissions.CHEQUE_SIGN, "action": "Approve", "description": "Authorize cheque signing & release above threshold"},
    {"module": "Document Studio", "code": Permissions.DOCUMENT_VIEW, "action": "View", "description": "View generated & archived documents"},
    {"module": "Document Studio", "code": Permissions.DOCUMENT_PREVIEW, "action": "Preview", "description": "Preview PDF layouts prior to issue"},
    {"module": "Document Studio", "code": Permissions.DOCUMENT_PRINT, "action": "Print", "description": "Print formatted documents"},
    {"module": "Document Studio", "code": Permissions.DOCUMENT_PDF, "action": "Download", "description": "Generate & download formal PDF files"},
    {"module": "Document Studio", "code": Permissions.DOCUMENT_EXPORT_EXCEL, "action": "Export", "description": "Export formatted XLSX workbooks"},
    {"module": "Document Studio", "code": Permissions.DOCUMENT_EXPORT_CSV, "action": "Export", "description": "Export sanitized CSV datasets"},
    {"module": "Document Studio", "code": Permissions.DOCUMENT_EXPORT_BULK, "action": "Export", "description": "Bulk PDF batch & bulk ZIP/XLSX export"},
    {"module": "Document Studio", "code": Permissions.DOCUMENT_TEMPLATE_CUSTOMIZE, "action": "Manage", "description": "Customize document templates, print & numbering settings"},
    {"module": "Document Studio", "code": Permissions.DOCUMENT_TEMPLATE_PUBLISH, "action": "Approve", "description": "Approve & publish document template versions"},
    {"module": "Document Studio", "code": Permissions.DOCUMENT_DELIVERY_CONFIGURE, "action": "Manage", "description": "Configure Email, WhatsApp & automated delivery rules"},
    {"module": "Document Studio", "code": Permissions.DOCUMENT_SEND_EMAIL, "action": "Send", "description": "Deliver documents via Email"},
    {"module": "Document Studio", "code": Permissions.DOCUMENT_SEND_WHATSAPP, "action": "Send", "description": "Deliver documents via WhatsApp"},
    {"module": "Document Studio", "code": Permissions.DOCUMENT_ARCHIVE_MANAGE, "action": "Manage", "description": "Manage document archive & retention policies"},
    {"module": "Document Studio", "code": Permissions.DOCUMENT_AUDIT_VIEW, "action": "View", "description": "Inspect print, export & delivery audit history"},
    {"module": "Chat Center", "code": Permissions.CHAT_VIEW, "action": "View", "description": "Access internal chat & company team rooms"},
    {"module": "Chat Center", "code": Permissions.CHAT_SEND, "action": "Create", "description": "Send chat messages & replies"},
    {"module": "Chat Center", "code": Permissions.CHAT_DM_CREATE, "action": "Create", "description": "Start direct 1:1 conversations"},
    {"module": "Chat Center", "code": Permissions.CHAT_GROUP_CREATE, "action": "Create", "description": "Create team/project/task group chats"},
    {"module": "Chat Center", "code": Permissions.CHAT_GROUP_MANAGE, "action": "Manage", "description": "Manage group members & settings"},
    {"module": "Chat Center", "code": Permissions.CHAT_CHANNEL_CREATE, "action": "Create", "description": "Create department/project/worksite channels"},
    {"module": "Chat Center", "code": Permissions.CHAT_CHANNEL_MANAGE, "action": "Manage", "description": "Manage All-Team & channel policies"},
    {"module": "Chat Center", "code": Permissions.CHAT_ATTACH, "action": "Create", "description": "Upload files & media attachments in chat"},
    {"module": "Chat Center", "code": Permissions.CHAT_SHARE_LINKS, "action": "Create", "description": "Attach authorized Maya OS page links in chat"},
    {"module": "Chat Center", "code": Permissions.CHAT_PIN, "action": "Manage", "description": "Pin announcements & messages in chat"},
    {"module": "Chat Center", "code": Permissions.CHAT_EDIT_OWN, "action": "Manage", "description": "Edit own chat messages within policy window"},
    {"module": "Chat Center", "code": Permissions.CHAT_DELETE_OWN, "action": "Manage", "description": "Delete own chat messages"},
    {"module": "Chat Center", "code": Permissions.CHAT_MODERATE, "action": "Approve", "description": "Moderate messages & mute restricted senders"},
    {"module": "Chat Center", "code": Permissions.CHAT_ADMIN_MANAGE, "action": "Manage", "description": "Configure global/company chat & retention policies"},
    {"module": "Chat Center", "code": Permissions.CHAT_EXPORT, "action": "Export", "description": "Export authorized chat transcripts"},
    {"module": "Chat Center", "code": Permissions.CHAT_AUDIT_VIEW, "action": "View", "description": "Inspect chat moderation & compliance audit logs"},
    {"module": "Notifications", "code": Permissions.NOTIFICATION_VIEW, "action": "View", "description": "View personal notification feed, alerts & preferences"},
    {"module": "Notifications", "code": Permissions.NOTIFICATION_ACTION_EXECUTE, "action": "Execute", "description": "Execute authorized actions directly from notifications"},
    {"module": "Notifications", "code": Permissions.NOTIFICATION_HISTORY_EXPORT, "action": "Export", "description": "Export authorized personal/system notification history"},
    {"module": "Notifications", "code": Permissions.NOTIFICATION_ADMIN_MANAGE, "action": "Manage", "description": "Manage notification center retention, escalation & audit logs"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_VIEW, "action": "View", "description": "View owned & rented vehicles, agreements, trips & fleet dashboard"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_CREATE, "action": "Create", "description": "Register owned & rented vehicles and vehicle documents"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_EDIT, "action": "Edit", "description": "Update vehicle master, status & asset links"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_ASSIGN_DRIVER, "action": "Manage", "description": "Register drivers/operators and assign vehicles"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_TRIP_CREATE, "action": "Create", "description": "Record vehicle trips, odometer & fuel usage"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_TRIP_VERIFY, "action": "Manage", "description": "Verify vehicle trip sheets at site"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_TRIP_APPROVE, "action": "Approve", "description": "Approve vehicle trips & finalize cost/income calculation"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_INCOME_RECORD, "action": "Create", "description": "Record vehicle hire income (Single Entry Cash & Customer Invoices)"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_INCOME_APPROVE, "action": "Approve", "description": "Approve vehicle income vouchers"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_RENTAL_MANAGE, "action": "Manage", "description": "Manage hired-in and hired-out rental agreements"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_RENTAL_EXPENSE_CREATE, "action": "Create", "description": "Record rented vehicle, fuel & maintenance expenses"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_RENTAL_EXPENSE_APPROVE, "action": "Approve", "description": "Approve rented vehicle & fleet expenses"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_CASH_ENTRY, "action": "Create", "description": "Create Single Entry quick Cash/Bank vehicle transactions"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_LEDGER_VIEW, "action": "View", "description": "Inspect vehicle operational ledgers & profitability"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_REPORTS_EXPORT, "action": "Export", "description": "Export fleet PDF, XLSX & CSV reports"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_TRIP_DISPATCH, "action": "Manage", "description": "Dispatch planned trips and vehicle assignments"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_TRIP_SUBMIT, "action": "Create", "description": "Submit driver trip completion & meter logs"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_FUEL_RECORD, "action": "Create", "description": "Record direct and warehouse fuel transactions"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_MAINT_CREATE, "action": "Create", "description": "Create maintenance work orders & service logs"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_MAINT_APPROVE, "action": "Approve", "description": "Approve maintenance work orders & expenses"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_VOUCHER_POST, "action": "Post", "description": "Post fleet accounting vouchers to General Ledger"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_REVERSE, "action": "Reverse", "description": "Reverse posted fleet transactions with audit reason"},
    {"module": "Vehicle & Fleet", "code": Permissions.VEHICLE_CONFIG_MANAGE, "action": "Manage", "description": "Configure Fleet Studio rules, categories & GL mappings"},
]

FINANCIAL_CONTROL_PERMISSIONS = {
    Permissions.VOUCHER_APPROVE,
    Permissions.VOUCHER_POST,
    Permissions.VOUCHER_REVERSE,
    Permissions.PERIOD_MANAGE,
    Permissions.COA_CONTROL_OVERRIDE,
}

ROLE_PRESETS: dict[str, dict] = {
    "SUPER_ADMIN": {
        "name": "Super Admin",
        "description": "Entire platform and company configuration",
        "template": "EXECUTIVE",
        "permissions": ALL_PERMISSIONS,
    },
    "COMPANY_ADMIN": {
        "name": "Company Admin",
        "description": "Company-level administration and access governance",
        "template": "EXECUTIVE",
        "permissions": [
            p
            for p in ALL_PERMISSIONS
            if p
            not in {
                Permissions.SYSTEM_MANAGE,
                Permissions.SUPER_ADMIN_MANAGE,
                Permissions.INSTALL_MANAGE,
                Permissions.UPDATE_MANAGE,
                Permissions.CALENDAR_DATASET_MANAGE,
                Permissions.RESTORE_EXECUTE,
            }
        ],
    },
    "FINANCE_DIRECTOR": {
        "name": "Finance Director",
        "description": "Multi-company financial supervision and high-value approval",
        "template": "FINANCE",
        "permissions": [
            Permissions.DASHBOARD_VIEW, Permissions.DASHBOARD_CUSTOMIZE,
            Permissions.PERIOD_MANAGE, Permissions.COA_READ, Permissions.COA_WRITE,
            Permissions.LEDGER_READ, Permissions.VOUCHER_READ, Permissions.VOUCHER_APPROVE,
            Permissions.VOUCHER_REJECT, Permissions.VOUCHER_RETURN, Permissions.VOUCHER_HOLD,
            Permissions.VOUCHER_POST, Permissions.VOUCHER_REVERSE,
            Permissions.COA_CONTROL_OVERRIDE, Permissions.PARTY_READ, Permissions.PARTY_WRITE,
            Permissions.DEBTORS_VIEW, Permissions.DEBTORS_MANAGE, Permissions.DEBTORS_COLLECT,
            Permissions.DEBTORS_APPROVE, Permissions.DEBTORS_WRITEOFF,
            Permissions.DEBTORS_CREDIT_OVERRIDE, Permissions.DEBTORS_RA_VERIFY,
            Permissions.DEBTORS_RA_CERTIFY, Permissions.DEBTORS_RECONCILE, Permissions.DEBTORS_CONFIG,
            Permissions.CREDITORS_VIEW, Permissions.CREDITORS_MANAGE, Permissions.CREDITORS_APPROVE,
            Permissions.CREDITORS_PAY_PLAN, Permissions.PARTY_RECONCILE_RUN, Permissions.PARTY_STATEMENT_CONFIRM,
            Permissions.VOUCHER_THEME_CUSTOMIZE, Permissions.VOUCHER_TYPE_MANAGE, Permissions.VOUCHER_CLASS_MANAGE,
            Permissions.VOUCHER_PROVISIONAL_MANAGE, Permissions.VOUCHER_SCENARIO_VIEW, Permissions.COST_CENTRE_MANAGE,
            Permissions.COA_INLINE_CREATE,
            Permissions.CONSTRUCTION_OPS_READ, Permissions.CONSTRUCTION_OPS_APPROVE,
            Permissions.VOUCHER_PRINT, Permissions.VOUCHER_EXPORT,
            Permissions.REPORT_READ, Permissions.REPORT_EXPORT,
            Permissions.REPORT_DASHBOARD_VIEW, Permissions.REPORT_TB_VIEW, Permissions.REPORT_GL_VIEW,
            Permissions.REPORT_PL_VIEW, Permissions.REPORT_BS_VIEW, Permissions.REPORT_VOUCHER_REG_VIEW,
            Permissions.REPORT_CONSTRUCTION_VIEW, Permissions.REPORT_AGING_VIEW, Permissions.REPORT_COST_CENTRE_VIEW,
            Permissions.REPORT_TAX_VIEW, Permissions.REPORT_AUDIT_VIEW, Permissions.REPORT_PRINT,
            Permissions.REPORT_BUILDER_MANAGE, Permissions.REPORT_BUILDER_SHARE, Permissions.REPORT_SCHEDULE_MANAGE,
            Permissions.REPORT_SENSITIVE_VIEW, Permissions.REPORT_CROSS_BRANCH, Permissions.REPORT_CROSS_PROJECT,
            Permissions.PROJECT_READ, Permissions.SITE_READ,
            Permissions.PROCUREMENT_READ, Permissions.PROCUREMENT_APPROVE, Permissions.PROCUREMENT_MATCH,
            Permissions.INVENTORY_READ, Permissions.INVENTORY_VALUATION,
            Permissions.HR_READ, Permissions.PAYROLL_APPROVE, Permissions.PAYROLL_POST,
            Permissions.HR_PAYROLL_SENSITIVE, Permissions.HR_SALARY_REVISION_APPROVE,
            Permissions.HR_PAYROLL_PAY, Permissions.HR_TAX_VIEW,
            Permissions.HR_FINAL_SETTLEMENT_APPROVE, Permissions.HR_REPORT_EXPORT,
            Permissions.BUDGET_READ, Permissions.BUDGET_WRITE, Permissions.BUDGET_APPROVE,
            Permissions.BUDGET_TRANSFER, Permissions.BUDGET_OVERRIDE,
            Permissions.AUDIT_READ, Permissions.AUTHORITY_MANAGE,
            Permissions.BANKING_READ, Permissions.BANKING_MANAGE,
            Permissions.CASH_READ, Permissions.CASH_MANAGE,
            Permissions.RECONCILIATION_MANAGE, Permissions.RECONCILIATION_APPROVE,
            Permissions.CHEQUE_READ, Permissions.CHEQUE_ISSUE, Permissions.CHEQUE_CLEAR, Permissions.CHEQUE_REVERSE,
            Permissions.FX_READ, Permissions.FX_MANAGE,
            Permissions.LOAN_READ, Permissions.LOAN_MANAGE, Permissions.LOAN_APPROVE,
            Permissions.LOAN_RATE_APPROVE, Permissions.INTEREST_POST,
            Permissions.BG_READ, Permissions.BG_MANAGE, Permissions.BG_APPROVE, Permissions.BG_RELEASE,
            Permissions.COLLATERAL_MANAGE, Permissions.COLLATERAL_RELEASE,
            Permissions.TREASURY_CONFIG, Permissions.TREASURY_APPROVE,
            Permissions.OPENING_BALANCE_VIEW, Permissions.OPENING_BALANCE_MANAGE,
            Permissions.OPENING_BALANCE_APPROVE, Permissions.OPENING_BALANCE_POST,
            Permissions.OPENING_BALANCE_REVERSE, Permissions.OPENING_BALANCE_DIRECTION_OVERRIDE,
            Permissions.OPENING_BALANCE_MIGRATION_OVERRIDE, Permissions.OPENING_BALANCE_CARRY_FORWARD,
            Permissions.CASH_HANDOVER_APPROVE, Permissions.RECONCILIATION_REOPEN,
            Permissions.FX_OVERRIDE_APPROVE, Permissions.CHEQUE_SIGN,
            Permissions.DOCUMENT_VIEW, Permissions.DOCUMENT_PREVIEW, Permissions.DOCUMENT_PRINT,
            Permissions.DOCUMENT_PDF, Permissions.DOCUMENT_EXPORT_EXCEL, Permissions.DOCUMENT_EXPORT_CSV,
            Permissions.DOCUMENT_EXPORT_BULK, Permissions.DOCUMENT_TEMPLATE_CUSTOMIZE,
            Permissions.DOCUMENT_TEMPLATE_PUBLISH, Permissions.DOCUMENT_DELIVERY_CONFIGURE,
            Permissions.DOCUMENT_SEND_EMAIL, Permissions.DOCUMENT_SEND_WHATSAPP,
            Permissions.DOCUMENT_ARCHIVE_MANAGE, Permissions.DOCUMENT_AUDIT_VIEW,
            Permissions.SYNC_PULL,
        ],
    },
    "FINANCE_MANAGER": {
        "name": "Finance Manager",
        "description": "Financial controls, approvals, posting, and reporting",
        "template": "FINANCE",
        "permissions": [
            Permissions.DASHBOARD_VIEW, Permissions.DASHBOARD_CUSTOMIZE,
            Permissions.PERIOD_MANAGE, Permissions.COA_READ, Permissions.COA_WRITE,
            Permissions.LEDGER_READ, Permissions.VOUCHER_READ, Permissions.VOUCHER_CREATE,
            Permissions.VOUCHER_EDIT, Permissions.VOUCHER_SUBMIT, Permissions.VOUCHER_APPROVE,
            Permissions.VOUCHER_REJECT, Permissions.VOUCHER_RETURN, Permissions.VOUCHER_HOLD,
            Permissions.VOUCHER_POST, Permissions.VOUCHER_REVERSE,
            Permissions.PARTY_READ, Permissions.PARTY_WRITE, Permissions.VOUCHER_THEME_CUSTOMIZE, Permissions.VOUCHER_DESIGN_MANAGE,
            Permissions.VOUCHER_TYPE_MANAGE, Permissions.VOUCHER_CLASS_MANAGE, Permissions.VOUCHER_PROVISIONAL_MANAGE,
            Permissions.VOUCHER_SCENARIO_VIEW, Permissions.COST_CENTRE_MANAGE, Permissions.COA_INLINE_CREATE,
            Permissions.OPENING_BALANCE_VIEW, Permissions.OPENING_BALANCE_MANAGE, Permissions.OPENING_BALANCE_APPROVE,
            Permissions.OPENING_BALANCE_POST, Permissions.OPENING_BALANCE_REVERSE,
            Permissions.OPENING_BALANCE_DIRECTION_OVERRIDE, Permissions.OPENING_BALANCE_MIGRATION_OVERRIDE,
            Permissions.OPENING_BALANCE_CARRY_FORWARD,
            Permissions.DEBTORS_VIEW, Permissions.DEBTORS_MANAGE, Permissions.DEBTORS_COLLECT,
            Permissions.DEBTORS_APPROVE, Permissions.DEBTORS_WRITEOFF,
            Permissions.DEBTORS_CREDIT_OVERRIDE, Permissions.DEBTORS_RA_VERIFY,
            Permissions.DEBTORS_RA_CERTIFY, Permissions.DEBTORS_RECONCILE, Permissions.DEBTORS_CONFIG,
            Permissions.CREDITORS_VIEW, Permissions.CREDITORS_MANAGE, Permissions.CREDITORS_APPROVE,
            Permissions.CREDITORS_PAY_PLAN, Permissions.PARTY_RECONCILE_RUN, Permissions.PARTY_STATEMENT_CONFIRM,
            Permissions.CONSTRUCTION_OPS_READ, Permissions.CONSTRUCTION_OPS_APPROVE,
            Permissions.VOUCHER_PRINT, Permissions.VOUCHER_EXPORT,
            Permissions.REPORT_READ, Permissions.REPORT_EXPORT,
            Permissions.REPORT_DASHBOARD_VIEW, Permissions.REPORT_TB_VIEW, Permissions.REPORT_GL_VIEW,
            Permissions.REPORT_PL_VIEW, Permissions.REPORT_BS_VIEW, Permissions.REPORT_VOUCHER_REG_VIEW,
            Permissions.REPORT_CONSTRUCTION_VIEW, Permissions.REPORT_AGING_VIEW, Permissions.REPORT_COST_CENTRE_VIEW,
            Permissions.REPORT_TAX_VIEW, Permissions.REPORT_AUDIT_VIEW, Permissions.REPORT_PRINT,
            Permissions.REPORT_BUILDER_MANAGE, Permissions.REPORT_BUILDER_SHARE, Permissions.REPORT_SCHEDULE_MANAGE,
            Permissions.REPORT_SENSITIVE_VIEW, Permissions.REPORT_CROSS_BRANCH, Permissions.REPORT_CROSS_PROJECT,
            Permissions.PROJECT_READ, Permissions.SITE_READ,
            Permissions.PROCUREMENT_READ, Permissions.PROCUREMENT_APPROVE, Permissions.PROCUREMENT_MATCH,
            Permissions.INVENTORY_READ, Permissions.INVENTORY_VALUATION,
            Permissions.HR_READ, Permissions.PAYROLL_APPROVE, Permissions.PAYROLL_POST,
            Permissions.HR_PAYROLL_SENSITIVE, Permissions.HR_SALARY_REVISION_APPROVE,
            Permissions.HR_PAYROLL_PAY, Permissions.HR_TAX_VIEW,
            Permissions.HR_FINAL_SETTLEMENT_APPROVE, Permissions.HR_REPORT_EXPORT,
            Permissions.BUDGET_READ, Permissions.BUDGET_WRITE, Permissions.BUDGET_APPROVE,
            Permissions.BUDGET_TRANSFER, Permissions.AUDIT_READ,
            Permissions.BANKING_READ, Permissions.BANKING_MANAGE,
            Permissions.CASH_READ, Permissions.CASH_MANAGE,
            Permissions.RECONCILIATION_MANAGE, Permissions.RECONCILIATION_APPROVE,
            Permissions.CHEQUE_READ, Permissions.CHEQUE_ISSUE, Permissions.CHEQUE_CLEAR, Permissions.CHEQUE_REVERSE,
            Permissions.FX_READ, Permissions.FX_MANAGE,
            Permissions.LOAN_READ, Permissions.LOAN_MANAGE, Permissions.LOAN_APPROVE,
            Permissions.LOAN_RATE_APPROVE, Permissions.INTEREST_POST,
            Permissions.BG_READ, Permissions.BG_MANAGE, Permissions.BG_APPROVE, Permissions.BG_RELEASE,
            Permissions.COLLATERAL_MANAGE, Permissions.COLLATERAL_RELEASE,
            Permissions.TREASURY_CONFIG, Permissions.TREASURY_APPROVE,
            Permissions.OPENING_BALANCE_VIEW, Permissions.OPENING_BALANCE_MANAGE,
            Permissions.OPENING_BALANCE_APPROVE, Permissions.OPENING_BALANCE_POST,
            Permissions.OPENING_BALANCE_REVERSE, Permissions.OPENING_BALANCE_DIRECTION_OVERRIDE,
            Permissions.OPENING_BALANCE_MIGRATION_OVERRIDE, Permissions.OPENING_BALANCE_CARRY_FORWARD,
            Permissions.CASH_HANDOVER_APPROVE, Permissions.RECONCILIATION_REOPEN,
            Permissions.FX_OVERRIDE_APPROVE, Permissions.CHEQUE_SIGN,
            Permissions.DOCUMENT_VIEW, Permissions.DOCUMENT_PREVIEW, Permissions.DOCUMENT_PRINT,
            Permissions.DOCUMENT_PDF, Permissions.DOCUMENT_EXPORT_EXCEL, Permissions.DOCUMENT_EXPORT_CSV,
            Permissions.DOCUMENT_EXPORT_BULK, Permissions.DOCUMENT_TEMPLATE_CUSTOMIZE,
            Permissions.DOCUMENT_TEMPLATE_PUBLISH, Permissions.DOCUMENT_DELIVERY_CONFIGURE,
            Permissions.DOCUMENT_SEND_EMAIL, Permissions.DOCUMENT_SEND_WHATSAPP,
            Permissions.DOCUMENT_ARCHIVE_MANAGE, Permissions.DOCUMENT_AUDIT_VIEW,
            Permissions.SYNC_PUSH, Permissions.SYNC_PULL,
        ],
    },
    "CHIEF_ACCOUNTANT": {
        "name": "Chief Accountant",
        "description": "Accounting control, ledger verification, and posting",
        "template": "ACCOUNTING",
        "permissions": [
            Permissions.DASHBOARD_VIEW, Permissions.DASHBOARD_CUSTOMIZE,
            Permissions.COA_READ, Permissions.COA_WRITE, Permissions.LEDGER_READ,
            Permissions.VOUCHER_PROVISIONAL_MANAGE, Permissions.VOUCHER_SCENARIO_VIEW, Permissions.COA_INLINE_CREATE,
            Permissions.OPENING_BALANCE_VIEW, Permissions.OPENING_BALANCE_MANAGE, Permissions.OPENING_BALANCE_POST,
            Permissions.VOUCHER_READ, Permissions.VOUCHER_CREATE, Permissions.VOUCHER_EDIT,
            Permissions.VOUCHER_SUBMIT, Permissions.VOUCHER_APPROVE, Permissions.VOUCHER_POST,
            Permissions.VOUCHER_PRINT, Permissions.VOUCHER_EXPORT,
            Permissions.PARTY_READ, Permissions.PARTY_WRITE, Permissions.CONSTRUCTION_OPS_READ,
            Permissions.DEBTORS_VIEW, Permissions.DEBTORS_MANAGE, Permissions.DEBTORS_COLLECT,
            Permissions.DEBTORS_RA_CERTIFY, Permissions.DEBTORS_RECONCILE,
            Permissions.CREDITORS_VIEW, Permissions.CREDITORS_MANAGE, Permissions.CREDITORS_PAY_PLAN,
            Permissions.PARTY_RECONCILE_RUN,
            Permissions.REPORT_READ, Permissions.REPORT_EXPORT,
            Permissions.REPORT_DASHBOARD_VIEW, Permissions.REPORT_TB_VIEW, Permissions.REPORT_GL_VIEW,
            Permissions.REPORT_PL_VIEW, Permissions.REPORT_BS_VIEW, Permissions.REPORT_VOUCHER_REG_VIEW,
            Permissions.REPORT_CONSTRUCTION_VIEW, Permissions.REPORT_AGING_VIEW, Permissions.REPORT_COST_CENTRE_VIEW,
            Permissions.REPORT_TAX_VIEW, Permissions.REPORT_AUDIT_VIEW, Permissions.REPORT_PRINT,
            Permissions.REPORT_BUILDER_MANAGE,
            Permissions.PROJECT_READ, Permissions.SITE_READ, Permissions.BUDGET_READ,
            Permissions.BANKING_READ, Permissions.BANKING_MANAGE,
            Permissions.CASH_READ, Permissions.CASH_MANAGE,
            Permissions.RECONCILIATION_MANAGE, Permissions.CHEQUE_READ, Permissions.CHEQUE_ISSUE, Permissions.CHEQUE_CLEAR,
            Permissions.FX_READ, Permissions.LOAN_READ, Permissions.BG_READ,
            Permissions.BG_MANAGE, Permissions.COLLATERAL_MANAGE, Permissions.INTEREST_POST,
            Permissions.DOCUMENT_VIEW, Permissions.DOCUMENT_PREVIEW, Permissions.DOCUMENT_PRINT,
            Permissions.DOCUMENT_PDF, Permissions.DOCUMENT_EXPORT_EXCEL, Permissions.DOCUMENT_EXPORT_CSV,
            Permissions.DOCUMENT_SEND_EMAIL, Permissions.DOCUMENT_AUDIT_VIEW,
            Permissions.SYNC_PUSH, Permissions.SYNC_PULL,
        ],
    },
    "ACCOUNTANT": {
        "name": "Accountant",
        "description": "Vouchers, ledgers, and financial reports",
        "template": "ACCOUNTING",
        "permissions": [
            Permissions.DASHBOARD_VIEW, Permissions.DASHBOARD_CUSTOMIZE,
            Permissions.COA_READ, Permissions.COA_WRITE, Permissions.LEDGER_READ,
            Permissions.VOUCHER_PROVISIONAL_MANAGE, Permissions.VOUCHER_SCENARIO_VIEW, Permissions.COA_INLINE_CREATE,
            Permissions.OPENING_BALANCE_VIEW, Permissions.OPENING_BALANCE_MANAGE, Permissions.OPENING_BALANCE_POST,
            Permissions.VOUCHER_READ, Permissions.VOUCHER_CREATE, Permissions.VOUCHER_EDIT,
            Permissions.VOUCHER_DELETE, Permissions.VOUCHER_SUBMIT, Permissions.VOUCHER_PRINT,
            Permissions.REPORT_READ, Permissions.REPORT_TB_VIEW, Permissions.REPORT_GL_VIEW,
            Permissions.REPORT_VOUCHER_REG_VIEW, Permissions.REPORT_AGING_VIEW, Permissions.REPORT_COST_CENTRE_VIEW,
            Permissions.REPORT_TAX_VIEW, Permissions.REPORT_PRINT,
            Permissions.PROJECT_READ, Permissions.SITE_READ,
            Permissions.PARTY_READ, Permissions.PARTY_WRITE,
            Permissions.DEBTORS_VIEW, Permissions.DEBTORS_MANAGE, Permissions.DEBTORS_COLLECT,
            Permissions.DEBTORS_RECONCILE,
            Permissions.CREDITORS_VIEW, Permissions.CREDITORS_MANAGE, Permissions.CREDITORS_PAY_PLAN,
            Permissions.PARTY_RECONCILE_RUN,
            Permissions.PROCUREMENT_READ, Permissions.INVENTORY_READ, Permissions.INVENTORY_VALUATION,
            Permissions.HR_READ, Permissions.PAYROLL_CALCULATE, Permissions.BUDGET_READ,
            Permissions.BANKING_READ, Permissions.CASH_READ, Permissions.CASH_MANAGE,
            Permissions.RECONCILIATION_MANAGE, Permissions.CHEQUE_READ, Permissions.CHEQUE_ISSUE, Permissions.CHEQUE_CLEAR,
            Permissions.FX_READ, Permissions.LOAN_READ, Permissions.BG_READ,
            Permissions.DOCUMENT_VIEW, Permissions.DOCUMENT_PREVIEW, Permissions.DOCUMENT_PRINT,
            Permissions.DOCUMENT_PDF, Permissions.DOCUMENT_EXPORT_EXCEL, Permissions.DOCUMENT_EXPORT_CSV,
            Permissions.DOCUMENT_SEND_EMAIL, Permissions.DOCUMENT_AUDIT_VIEW,
            Permissions.SYNC_PUSH, Permissions.SYNC_PULL,
        ],
    },
    "PROJECT_DIRECTOR": {
        "name": "Project Director",
        "description": "Multi-project financial oversight and budget approvals",
        "template": "PROJECT",
        "permissions": [
            Permissions.DASHBOARD_VIEW, Permissions.DASHBOARD_CUSTOMIZE,
            Permissions.PROJECT_READ, Permissions.PROJECT_WRITE,
            Permissions.PROJECT_CONTRACT_MANAGE, Permissions.PROJECT_VARIATION_APPROVE,
            Permissions.PROJECT_DSR_APPROVE, Permissions.PROJECT_BUDGET_MANAGE,
            Permissions.SITE_READ, Permissions.SITE_WRITE,
            Permissions.BUDGET_READ, Permissions.BUDGET_WRITE,
            Permissions.VOUCHER_READ, Permissions.VOUCHER_APPROVE,
            Permissions.DEBTORS_VIEW, Permissions.DEBTORS_RA_VERIFY, Permissions.DEBTORS_RA_CERTIFY,
            Permissions.LEDGER_READ, Permissions.REPORT_READ,
            Permissions.REPORT_CONSTRUCTION_VIEW, Permissions.REPORT_AGING_VIEW, Permissions.REPORT_COST_CENTRE_VIEW,
            Permissions.DOCUMENT_VIEW, Permissions.DOCUMENT_PREVIEW, Permissions.DOCUMENT_PRINT,
            Permissions.DOCUMENT_PDF, Permissions.DOCUMENT_EXPORT_EXCEL,
            Permissions.SYNC_PULL,
        ],
    },
    "PROJECT_MANAGER": {
        "name": "Project Manager",
        "description": "Assigned project budgets, costs, and site management",
        "template": "PROJECT",
        "permissions": [
            Permissions.DASHBOARD_VIEW, Permissions.DASHBOARD_CUSTOMIZE,
            Permissions.COA_READ, Permissions.VOUCHER_READ, Permissions.VOUCHER_CREATE,
            Permissions.VOUCHER_EDIT, Permissions.VOUCHER_SUBMIT,
            Permissions.LEDGER_READ, Permissions.REPORT_READ,
            Permissions.REPORT_CONSTRUCTION_VIEW, Permissions.REPORT_COST_CENTRE_VIEW,
            Permissions.PROJECT_READ, Permissions.PROJECT_WRITE,
            Permissions.PROJECT_CONTRACT_MANAGE, Permissions.PROJECT_DSR_APPROVE,
            Permissions.PROJECT_BUDGET_MANAGE,
            Permissions.SITE_READ, Permissions.SITE_WRITE,
            Permissions.PROCUREMENT_READ, Permissions.PROCUREMENT_APPROVE,
            Permissions.DEBTORS_VIEW, Permissions.DEBTORS_RA_VERIFY, Permissions.CREDITORS_VIEW,
            Permissions.INVENTORY_READ, Permissions.INVENTORY_APPROVE,
            Permissions.HR_READ, Permissions.TIMESHEET_APPROVE,
            Permissions.BUDGET_READ, Permissions.SYNC_PUSH, Permissions.SYNC_PULL,
        ],
    },
    "SITE_ENGINEER": {
        "name": "Site Engineer",
        "description": "Assigned site activity, measurements, and expense requests",
        "template": "SITE",
        "permissions": [
            Permissions.DASHBOARD_VIEW, Permissions.COA_READ,
            Permissions.VOUCHER_READ, Permissions.VOUCHER_CREATE,
            Permissions.PROJECT_READ, Permissions.SITE_READ,
            Permissions.DEBTORS_VIEW, Permissions.DEBTORS_RA_VERIFY,
            Permissions.INVENTORY_READ, Permissions.SYNC_PUSH, Permissions.SYNC_PULL,
        ],
    },
    "SITE_SUPERVISOR": {
        "name": "Site Supervisor",
        "description": "Assigned site expenses, materials, and offline drafts",
        "template": "SITE",
        "permissions": [
            Permissions.DASHBOARD_VIEW, Permissions.COA_READ,
            Permissions.VOUCHER_READ, Permissions.VOUCHER_CREATE,
            Permissions.PROJECT_READ, Permissions.SITE_READ,
            Permissions.PROCUREMENT_READ, Permissions.PROCUREMENT_WRITE,
            Permissions.INVENTORY_READ, Permissions.INVENTORY_WRITE,
            Permissions.HR_READ, Permissions.HR_WRITE,
            Permissions.BUDGET_READ, Permissions.SYNC_PUSH, Permissions.SYNC_PULL,
        ],
    },
    "HR_MANAGER": {
        "name": "HR Manager",
        "description": "Employees, onboarding, department templates, attendance, and payroll management",
        "template": "HR",
        "permissions": [
            Permissions.DASHBOARD_VIEW, Permissions.HR_READ, Permissions.HR_WRITE,
            Permissions.HR_STAFF_ONBOARD, Permissions.HR_STAFF_CODE_RESET,
            Permissions.HR_DEPT_TEMPLATE_MANAGE, Permissions.HR_PROFILE_APPROVE,
            Permissions.HR_PAYROLL_SENSITIVE, Permissions.TIMESHEET_APPROVE,
            Permissions.PAYROLL_CALCULATE, Permissions.PAYROLL_APPROVE,
            Permissions.HR_CONTRACT_MANAGE, Permissions.HR_SALARY_STRUCTURE_MANAGE,
            Permissions.HR_SALARY_REVISION_APPROVE, Permissions.HR_ATTENDANCE_APPROVE,
            Permissions.HR_OVERTIME_APPROVE, Permissions.HR_LEAVE_APPROVE,
            Permissions.HR_PAYSLIP_DOWNLOAD, Permissions.HR_TAX_VIEW,
            Permissions.HR_ADVANCE_MANAGE, Permissions.HR_FINAL_SETTLEMENT_APPROVE,
            Permissions.HR_REPORT_EXPORT, Permissions.HR_CONFIG_MANAGE,
            Permissions.VOUCHER_READ, Permissions.PROJECT_READ, Permissions.REPORT_READ, Permissions.BUDGET_READ,
        ],
    },
    "PROCUREMENT_MANAGER": {
        "name": "Procurement Manager",
        "description": "Procurement, suppliers, and purchase requisitions",
        "template": "PROCUREMENT",
        "permissions": [
            Permissions.DASHBOARD_VIEW, Permissions.PROCUREMENT_READ, Permissions.PROCUREMENT_WRITE,
            Permissions.PROCUREMENT_APPROVE, Permissions.PROCUREMENT_MATCH, Permissions.VENDOR_APPROVE,
            Permissions.CREDITORS_VIEW, Permissions.CREDITORS_MANAGE, Permissions.CREDITORS_APPROVE,
            Permissions.COA_READ, Permissions.VOUCHER_READ, Permissions.VOUCHER_CREATE,
            Permissions.VOUCHER_SUBMIT, Permissions.PROJECT_READ, Permissions.INVENTORY_READ,
            Permissions.BUDGET_READ, Permissions.SYNC_PUSH, Permissions.SYNC_PULL,
        ],
    },
    "PROCUREMENT_OFFICER": {
        "name": "Procurement Officer",
        "description": "Suppliers, requisitions, and purchases",
        "template": "PROCUREMENT",
        "permissions": [
            Permissions.DASHBOARD_VIEW, Permissions.PROCUREMENT_READ,
            Permissions.CREDITORS_VIEW, Permissions.CREDITORS_MANAGE,
            Permissions.COA_READ, Permissions.VOUCHER_READ, Permissions.VOUCHER_CREATE,
            Permissions.VOUCHER_SUBMIT, Permissions.PROJECT_READ,
            Permissions.SYNC_PUSH, Permissions.SYNC_PULL,
        ],
    },
    "COLLECTION_OFFICER": {
        "name": "Collection Officer",
        "description": "Sundry Debtors follow-ups, commitments, statements, and disputes",
        "template": "FINANCE",
        "permissions": [
            Permissions.DASHBOARD_VIEW, Permissions.PARTY_READ,
            Permissions.DEBTORS_VIEW, Permissions.DEBTORS_COLLECT,
            Permissions.VOUCHER_READ, Permissions.REPORT_AGING_VIEW,
            Permissions.PROJECT_READ, Permissions.DOCUMENT_VIEW,
            Permissions.DOCUMENT_PREVIEW, Permissions.DOCUMENT_PDF, Permissions.DOCUMENT_SEND_EMAIL,
        ],
    },
    "STOREKEEPER": {
        "name": "Storekeeper",
        "description": "Assigned stores, inventory, GRN, and material transfers",
        "template": "INVENTORY",
        "permissions": [
            Permissions.DASHBOARD_VIEW, Permissions.INVENTORY_READ, Permissions.INVENTORY_WRITE,
            Permissions.INVENTORY_APPROVE, Permissions.INVENTORY_ADJUST, Permissions.INVENTORY_VALUATION,
            Permissions.PROCUREMENT_READ, Permissions.PROJECT_READ, Permissions.SITE_READ,
            Permissions.BUDGET_READ, Permissions.SYNC_PUSH, Permissions.SYNC_PULL,
        ],
    },
    "AUDITOR": {
        "name": "Auditor",
        "description": "Read-only accounting, financial reports, and audit inspection",
        "template": "AUDITOR",
        "permissions": [
            Permissions.DASHBOARD_VIEW, Permissions.COA_READ,
            Permissions.PARTY_READ, Permissions.DEBTORS_VIEW, Permissions.CREDITORS_VIEW, Permissions.CHEQUE_READ,
            Permissions.VOUCHER_READ, Permissions.VOUCHER_PRINT,
            Permissions.LEDGER_READ, Permissions.REPORT_READ, Permissions.REPORT_EXPORT, Permissions.VOUCHER_SCENARIO_VIEW,
            Permissions.REPORT_DASHBOARD_VIEW, Permissions.REPORT_TB_VIEW, Permissions.REPORT_GL_VIEW,
            Permissions.REPORT_PL_VIEW, Permissions.REPORT_BS_VIEW, Permissions.REPORT_VOUCHER_REG_VIEW,
            Permissions.REPORT_CONSTRUCTION_VIEW, Permissions.REPORT_AGING_VIEW, Permissions.REPORT_COST_CENTRE_VIEW,
            Permissions.REPORT_TAX_VIEW, Permissions.REPORT_AUDIT_VIEW, Permissions.REPORT_PRINT,
            Permissions.PROJECT_READ, Permissions.SITE_READ, Permissions.AUDIT_READ,
            Permissions.DOCUMENT_VIEW, Permissions.DOCUMENT_PREVIEW, Permissions.DOCUMENT_PRINT,
            Permissions.DOCUMENT_PDF, Permissions.DOCUMENT_EXPORT_EXCEL, Permissions.DOCUMENT_EXPORT_CSV,
            Permissions.DOCUMENT_AUDIT_VIEW,
        ],
    },
    "MANAGEMENT": {
        "name": "Management",
        "description": "Executive dashboard and management intelligence",
        "template": "EXECUTIVE",
        "permissions": [
            Permissions.DASHBOARD_VIEW, Permissions.DASHBOARD_CUSTOMIZE,
            Permissions.COA_READ, Permissions.PARTY_READ,
            Permissions.DEBTORS_VIEW, Permissions.CREDITORS_VIEW, Permissions.VOUCHER_READ,
            Permissions.LEDGER_READ, Permissions.REPORT_READ, Permissions.REPORT_EXPORT, Permissions.VOUCHER_SCENARIO_VIEW,
            Permissions.REPORT_DASHBOARD_VIEW, Permissions.REPORT_TB_VIEW, Permissions.REPORT_GL_VIEW,
            Permissions.REPORT_PL_VIEW, Permissions.REPORT_BS_VIEW, Permissions.REPORT_VOUCHER_REG_VIEW,
            Permissions.REPORT_CONSTRUCTION_VIEW, Permissions.REPORT_AGING_VIEW, Permissions.REPORT_COST_CENTRE_VIEW,
            Permissions.REPORT_TAX_VIEW, Permissions.REPORT_AUDIT_VIEW, Permissions.REPORT_PRINT,
            Permissions.PROJECT_READ, Permissions.SITE_READ, Permissions.BUDGET_READ,
            Permissions.DOCUMENT_VIEW, Permissions.DOCUMENT_PREVIEW, Permissions.DOCUMENT_PDF,
            Permissions.DOCUMENT_EXPORT_EXCEL,
        ],
    },
    "IT_ADMIN": {
        "name": "IT Administrator",
        "description": "Technical platform, devices, configuration, and backup administration without automatic financial authority",
        "template": "ADMIN",
        "permissions": [
            Permissions.DASHBOARD_VIEW,
            Permissions.ACCESS_VIEW, Permissions.ACCESS_MANAGE, Permissions.ROLE_MANAGE,
            Permissions.DEVICE_MANAGE, Permissions.AUDIT_READ,
            Permissions.SYSTEM_VIEW, Permissions.SYSTEM_CONFIG_MANAGE,
            Permissions.BACKUP_MANAGE, Permissions.SYSTEM_MANAGE,
        ],
    },
}

STANDARD_CHAT_PERMISSIONS = [
    Permissions.CHAT_VIEW,
    Permissions.CHAT_SEND,
    Permissions.CHAT_DM_CREATE,
    Permissions.CHAT_GROUP_CREATE,
    Permissions.CHAT_ATTACH,
    Permissions.CHAT_SHARE_LINKS,
    Permissions.CHAT_EDIT_OWN,
    Permissions.CHAT_DELETE_OWN,
]

for _rcode, _spec in ROLE_PRESETS.items():
    if _rcode == "AUDITOR":
        if Permissions.CHAT_VIEW not in _spec["permissions"]:
            _spec["permissions"].append(Permissions.CHAT_VIEW)
    else:
        for _perm in STANDARD_CHAT_PERMISSIONS:
            if _perm not in _spec["permissions"]:
                _spec["permissions"].append(_perm)
    if _rcode in ("PROJECT_DIRECTOR", "PROJECT_MANAGER", "FINANCE_DIRECTOR", "FINANCE_MANAGER", "HR_MANAGER"):
        for _perm in (Permissions.CHAT_GROUP_MANAGE, Permissions.CHAT_CHANNEL_CREATE, Permissions.CHAT_PIN):
            if _perm not in _spec["permissions"]:
                _spec["permissions"].append(_perm)

    if Permissions.NOTIFICATION_VIEW not in _spec["permissions"]:
        _spec["permissions"].append(Permissions.NOTIFICATION_VIEW)
    if _rcode != "AUDITOR" and Permissions.NOTIFICATION_ACTION_EXECUTE not in _spec["permissions"]:
        _spec["permissions"].append(Permissions.NOTIFICATION_ACTION_EXECUTE)
    if _rcode in ("FINANCE_DIRECTOR", "AUDITOR", "IT_ADMIN") and Permissions.NOTIFICATION_HISTORY_EXPORT not in _spec["permissions"]:
        _spec["permissions"].append(Permissions.NOTIFICATION_HISTORY_EXPORT)
    if _rcode == "IT_ADMIN" and Permissions.NOTIFICATION_ADMIN_MANAGE not in _spec["permissions"]:
        _spec["permissions"].append(Permissions.NOTIFICATION_ADMIN_MANAGE)

    if _rcode in ("PROJECT_DIRECTOR", "PROJECT_MANAGER", "FINANCE_DIRECTOR", "FINANCE_MANAGER", "ACCOUNTANT", "SITE_SUPERVISOR", "PROCUREMENT_OFFICER"):
        for _vp in (Permissions.VEHICLE_VIEW, Permissions.VEHICLE_TRIP_CREATE, Permissions.VEHICLE_TRIP_SUBMIT, Permissions.VEHICLE_FUEL_RECORD, Permissions.VEHICLE_MAINT_CREATE, Permissions.VEHICLE_LEDGER_VIEW):
            if _vp not in _spec["permissions"]:
                _spec["permissions"].append(_vp)
    if _rcode in ("PROJECT_DIRECTOR", "PROJECT_MANAGER", "FINANCE_DIRECTOR", "FINANCE_MANAGER"):
        for _vp in (
            Permissions.VEHICLE_CREATE,
            Permissions.VEHICLE_EDIT,
            Permissions.VEHICLE_ASSIGN_DRIVER,
            Permissions.VEHICLE_TRIP_DISPATCH,
            Permissions.VEHICLE_TRIP_VERIFY,
            Permissions.VEHICLE_TRIP_APPROVE,
            Permissions.VEHICLE_INCOME_RECORD,
            Permissions.VEHICLE_INCOME_APPROVE,
            Permissions.VEHICLE_RENTAL_MANAGE,
            Permissions.VEHICLE_RENTAL_EXPENSE_CREATE,
            Permissions.VEHICLE_RENTAL_EXPENSE_APPROVE,
            Permissions.VEHICLE_MAINT_APPROVE,
            Permissions.VEHICLE_CASH_ENTRY,
            Permissions.VEHICLE_VOUCHER_POST,
            Permissions.VEHICLE_REVERSE,
            Permissions.VEHICLE_CONFIG_MANAGE,
            Permissions.VEHICLE_REPORTS_EXPORT,
        ):
            if _vp not in _spec["permissions"]:
                _spec["permissions"].append(_vp)
    if _rcode == "ACCOUNTANT":
        for _vp in (
            Permissions.VEHICLE_CREATE,
            Permissions.VEHICLE_INCOME_RECORD,
            Permissions.VEHICLE_RENTAL_EXPENSE_CREATE,
            Permissions.VEHICLE_CASH_ENTRY,
            Permissions.VEHICLE_REPORTS_EXPORT,
        ):
            if _vp not in _spec["permissions"]:
                _spec["permissions"].append(_vp)
    if _rcode == "SITE_SUPERVISOR" and Permissions.VEHICLE_TRIP_VERIFY not in _spec["permissions"]:
        _spec["permissions"].append(Permissions.VEHICLE_TRIP_VERIFY)
    if _rcode == "AUDITOR":
        for _vp in (Permissions.VEHICLE_VIEW, Permissions.VEHICLE_LEDGER_VIEW, Permissions.VEHICLE_REPORTS_EXPORT):
            if _vp not in _spec["permissions"]:
                _spec["permissions"].append(_vp)
