// Admin Console Permission Constants
// Granular permissions for DBIS and SCB admin consoles

export enum AdminPermission {
  // GRU Management
  GRU_CREATE_CLASS = 'gru:create_class',
  GRU_CHANGE_CLASS = 'gru:change_class',
  GRU_LOCK_UNLOCK = 'gru:lock_unlock',
  GRU_ISSUANCE_PROPOSAL = 'gru:issuance_proposal',
  GRU_INDEX_WEIGHT_ADJUST = 'gru:index_weight_adjust',
  GRU_CIRCUIT_BREAKERS = 'gru:circuit_breakers',
  GRU_BOND_ISSUANCE_WINDOW = 'gru:bond_issuance_window',
  GRU_BOND_BUYBACK = 'gru:bond_buyback',

  // Corridor Management
  CORRIDOR_ADJUST_CAPS = 'corridor:adjust_caps',
  CORRIDOR_THROTTLE = 'corridor:throttle',
  CORRIDOR_ENABLE_DISABLE = 'corridor:enable_disable',
  CORRIDOR_REQUEST_CHANGE = 'corridor:request_change',

  // Network Controls
  NETWORK_QUIESCE_SUBSYSTEM = 'network:quiesce_subsystem',
  NETWORK_KILL_SWITCH = 'network:kill_switch',
  NETWORK_ESCALATE_INCIDENT = 'network:escalate_incident',

  // SCB Management
  SCB_PAUSE_SETTLEMENT = 'scb:pause_settlement',
  SCB_VIEW_DETAILS = 'scb:view_details',
  SCB_IMPERSONATE_VIEW = 'scb:impersonate_view',
  SCB_JURISDICTION_SETTINGS = 'scb:jurisdiction_settings',

  // FI Management
  FI_APPROVE_SUSPEND = 'fi:approve_suspend',
  FI_SET_LIMITS = 'fi:set_limits',
  FI_API_PROFILES = 'fi:api_profiles',

  // CBDC Management
  CBDC_APPROVE_TYPE = 'cbdc:approve_type',
  CBDC_CROSS_BORDER_CORRIDOR = 'cbdc:cross_border_corridor',
  CBDC_UPDATE_PARAMETERS = 'cbdc:update_parameters',

  // GAS & QPS
  GAS_SET_LIMITS = 'gas:set_limits',
  GAS_ENABLE_DISABLE_SETTLEMENT = 'gas:enable_disable_settlement',
  GAS_THROTTLE_BANDWIDTH = 'gas:throttle_bandwidth',
  QPS_ENABLE_DISABLE = 'qps:enable_disable',
  QPS_SET_MAPPING_PROFILES = 'qps:set_mapping_profiles',

  // Metaverse & Edge
  METAVERSE_ENABLE_ONRAMP = 'metaverse:enable_onramp',
  METAVERSE_SET_LIMITS = 'metaverse:set_limits',
  EDGE_DRAIN_LOAD = 'edge:drain_load',
  EDGE_QUARANTINE = 'edge:quarantine',

  // Risk & Compliance
  RISK_ACKNOWLEDGE_ALERT = 'risk:acknowledge_alert',
  RISK_TRIGGER_STRESS_TEST = 'risk:trigger_stress_test',
  RISK_PUSH_POLICY_UPDATE = 'risk:push_policy_update',
  RISK_MARK_SCENARIO = 'risk:mark_scenario',

  // Nostro/Vostro
  NOSTRO_VOSTRO_OPEN = 'nostro_vostro:open',
  NOSTRO_VOSTRO_ADJUST_LIMITS = 'nostro_vostro:adjust_limits',
  NOSTRO_VOSTRO_FREEZE = 'nostro_vostro:freeze',

  // Developer & Integrations
  API_KEY_ROTATE = 'api:key_rotate',
  API_KEY_REVOKE = 'api:key_revoke',
  API_SANDBOX_MODE = 'api:sandbox_mode',

  // Security & Identity
  RBAC_EDIT = 'rbac:edit',
  AUDIT_EXPORT = 'audit:export',

  // Read-only permissions
  VIEW_GLOBAL_OVERVIEW = 'view:global_overview',
  VIEW_PARTICIPANTS = 'view:participants',
  VIEW_GRU_COMMAND = 'view:gru_command',
  VIEW_GAS_QPS = 'view:gas_qps',
  VIEW_CBDC_FX = 'view:cbdc_fx',
  VIEW_METAVERSE_EDGE = 'view:metaverse_edge',
  VIEW_RISK_COMPLIANCE = 'view:risk_compliance',
  VIEW_SCB_OVERVIEW = 'view:scb_overview',
  VIEW_FI_MANAGEMENT = 'view:fi_management',
  VIEW_CORRIDOR_POLICY = 'view:corridor_policy',
}

export enum AdminRole {
  DBIS_SUPER_ADMIN = 'DBIS_Super_Admin',
  DBIS_OPS = 'DBIS_Ops',
  DBIS_RISK = 'DBIS_Risk',
  SCB_ADMIN = 'SCB_Admin',
  SCB_RISK = 'SCB_Risk',
  SCB_TECH = 'SCB_Tech',
  SCB_READ_ONLY = 'SCB_Read_Only',
}

// Permission matrix: Role -> Permissions
export const ROLE_PERMISSIONS: Record<AdminRole, AdminPermission[]> = {
  [AdminRole.DBIS_SUPER_ADMIN]: [
    // All permissions
    AdminPermission.GRU_CREATE_CLASS,
    AdminPermission.GRU_CHANGE_CLASS,
    AdminPermission.GRU_LOCK_UNLOCK,
    AdminPermission.GRU_ISSUANCE_PROPOSAL,
    AdminPermission.GRU_INDEX_WEIGHT_ADJUST,
    AdminPermission.GRU_CIRCUIT_BREAKERS,
    AdminPermission.GRU_BOND_ISSUANCE_WINDOW,
    AdminPermission.GRU_BOND_BUYBACK,
    AdminPermission.CORRIDOR_ADJUST_CAPS,
    AdminPermission.CORRIDOR_THROTTLE,
    AdminPermission.CORRIDOR_ENABLE_DISABLE,
    AdminPermission.NETWORK_QUIESCE_SUBSYSTEM,
    AdminPermission.NETWORK_KILL_SWITCH,
    AdminPermission.NETWORK_ESCALATE_INCIDENT,
    AdminPermission.SCB_PAUSE_SETTLEMENT,
    AdminPermission.SCB_VIEW_DETAILS,
    AdminPermission.SCB_IMPERSONATE_VIEW,
    AdminPermission.SCB_JURISDICTION_SETTINGS,
    AdminPermission.FI_APPROVE_SUSPEND,
    AdminPermission.FI_SET_LIMITS,
    AdminPermission.FI_API_PROFILES,
    AdminPermission.CBDC_APPROVE_TYPE,
    AdminPermission.CBDC_CROSS_BORDER_CORRIDOR,
    AdminPermission.CBDC_UPDATE_PARAMETERS,
    AdminPermission.GAS_SET_LIMITS,
    AdminPermission.GAS_ENABLE_DISABLE_SETTLEMENT,
    AdminPermission.GAS_THROTTLE_BANDWIDTH,
    AdminPermission.QPS_ENABLE_DISABLE,
    AdminPermission.QPS_SET_MAPPING_PROFILES,
    AdminPermission.METAVERSE_ENABLE_ONRAMP,
    AdminPermission.METAVERSE_SET_LIMITS,
    AdminPermission.EDGE_DRAIN_LOAD,
    AdminPermission.EDGE_QUARANTINE,
    AdminPermission.RISK_ACKNOWLEDGE_ALERT,
    AdminPermission.RISK_TRIGGER_STRESS_TEST,
    AdminPermission.RISK_PUSH_POLICY_UPDATE,
    AdminPermission.RISK_MARK_SCENARIO,
    AdminPermission.NOSTRO_VOSTRO_OPEN,
    AdminPermission.NOSTRO_VOSTRO_ADJUST_LIMITS,
    AdminPermission.NOSTRO_VOSTRO_FREEZE,
    AdminPermission.API_KEY_ROTATE,
    AdminPermission.API_KEY_REVOKE,
    AdminPermission.API_SANDBOX_MODE,
    AdminPermission.RBAC_EDIT,
    AdminPermission.AUDIT_EXPORT,
    AdminPermission.VIEW_GLOBAL_OVERVIEW,
    AdminPermission.VIEW_PARTICIPANTS,
    AdminPermission.VIEW_GRU_COMMAND,
    AdminPermission.VIEW_GAS_QPS,
    AdminPermission.VIEW_CBDC_FX,
    AdminPermission.VIEW_METAVERSE_EDGE,
    AdminPermission.VIEW_RISK_COMPLIANCE,
    AdminPermission.VIEW_SCB_OVERVIEW,
    AdminPermission.VIEW_FI_MANAGEMENT,
    AdminPermission.VIEW_CORRIDOR_POLICY,
  ],
  [AdminRole.DBIS_OPS]: [
    AdminPermission.VIEW_GLOBAL_OVERVIEW,
    AdminPermission.VIEW_PARTICIPANTS,
    AdminPermission.VIEW_GAS_QPS,
    AdminPermission.VIEW_METAVERSE_EDGE,
    AdminPermission.NETWORK_ESCALATE_INCIDENT,
    AdminPermission.GAS_THROTTLE_BANDWIDTH,
    AdminPermission.QPS_ENABLE_DISABLE,
    AdminPermission.EDGE_DRAIN_LOAD,
    AdminPermission.RISK_ACKNOWLEDGE_ALERT,
  ],
  [AdminRole.DBIS_RISK]: [
    AdminPermission.VIEW_GLOBAL_OVERVIEW,
    AdminPermission.VIEW_RISK_COMPLIANCE,
    AdminPermission.RISK_ACKNOWLEDGE_ALERT,
    AdminPermission.RISK_TRIGGER_STRESS_TEST,
    AdminPermission.RISK_MARK_SCENARIO,
    AdminPermission.AUDIT_EXPORT,
  ],
  [AdminRole.SCB_ADMIN]: [
    AdminPermission.VIEW_SCB_OVERVIEW,
    AdminPermission.VIEW_FI_MANAGEMENT,
    AdminPermission.VIEW_CORRIDOR_POLICY,
    AdminPermission.FI_APPROVE_SUSPEND,
    AdminPermission.FI_SET_LIMITS,
    AdminPermission.FI_API_PROFILES,
    AdminPermission.CORRIDOR_REQUEST_CHANGE,
    AdminPermission.CBDC_UPDATE_PARAMETERS,
    AdminPermission.NOSTRO_VOSTRO_OPEN,
    AdminPermission.NOSTRO_VOSTRO_ADJUST_LIMITS,
    AdminPermission.NOSTRO_VOSTRO_FREEZE,
    AdminPermission.API_KEY_ROTATE,
    AdminPermission.API_KEY_REVOKE,
    AdminPermission.API_SANDBOX_MODE,
    AdminPermission.RISK_ACKNOWLEDGE_ALERT,
    AdminPermission.RISK_TRIGGER_STRESS_TEST,
  ],
  [AdminRole.SCB_RISK]: [
    AdminPermission.VIEW_SCB_OVERVIEW,
    AdminPermission.VIEW_FI_MANAGEMENT,
    AdminPermission.VIEW_CORRIDOR_POLICY,
    AdminPermission.RISK_ACKNOWLEDGE_ALERT,
    AdminPermission.RISK_MARK_SCENARIO,
    AdminPermission.RISK_TRIGGER_STRESS_TEST,
  ],
  [AdminRole.SCB_TECH]: [
    AdminPermission.VIEW_SCB_OVERVIEW,
    AdminPermission.VIEW_FI_MANAGEMENT,
    AdminPermission.FI_API_PROFILES,
    AdminPermission.API_KEY_ROTATE,
    AdminPermission.API_KEY_REVOKE,
    AdminPermission.API_SANDBOX_MODE,
  ],
  [AdminRole.SCB_READ_ONLY]: [
    AdminPermission.VIEW_SCB_OVERVIEW,
    AdminPermission.VIEW_FI_MANAGEMENT,
    AdminPermission.VIEW_CORRIDOR_POLICY,
  ],
};

