/** OMNL central-bank settlement domain types */

export type MoneyLayer = 'M0' | 'M1' | 'M2' | 'M00';

export type PaymentRail =
  | 'SWIFT'
  | 'SEPA'
  | 'TARGET2'
  | 'RTGS'
  | 'ACH'
  | 'FEDWIRE'
  | 'INTERNAL'
  | 'CHAIN138';

export type TradeFinanceInstrument = 'SBLC' | 'DLC' | 'BG' | 'LS';

export type SwiftMessageKind = 'MT103' | 'MT102' | 'MT202' | 'MT910';

export type SettlementPhase =
  | 'RECEIVED'
  | 'VALIDATED'
  | 'VERBIAGE_ROLLED'
  | 'FINERACT_POSTED'
  | 'HYBX_RAIL_DISPATCHED'
  | 'ISO20022_ARCHIVED'
  | 'CHAIN_MINT_REQUESTED'
  | 'SETTLED'
  | 'FAILED';

export type ExternalTransferRequest = {
  idempotencyKey: string;
  officeId: number;
  valueDate: string;
  currency: string;
  amount: string;
  debtorIban?: string;
  creditorIban: string;
  creditorBic?: string;
  beneficiaryName: string;
  orderingName?: string;
  remittanceInfo: string;
  moneyLayers: MoneyLayer[];
  rail: PaymentRail;
  swiftMessageKind?: SwiftMessageKind;
  tradeFinance?: {
    instrument: TradeFinanceInstrument;
    reference: string;
    expiryDate?: string;
  };
  rwaVerbiage?: {
    assetClass: string;
    tokenLineId: string;
    externalTransferRoll: boolean;
  };
  convertToCrypto?: {
    enabled: boolean;
    targetChainId: number;
    tokenLineId: string;
    recipientAddress: string;
  };
};

export type TokenLoadRequest = {
  idempotencyKey: string;
  officeId?: number;
  lineId: string;
  symbol?: string;
  tokenAddress?: string;
  amount: string;
  recipientAddress: string;
  currency?: string;
};

export type TransferRequest = {
  idempotencyKey: string;
  officeId?: number;
  tokenAddress: string;
  tokenSymbol: string;
  amount: string;
  recipientAddress: string;
  senderAddress?: string;
  moneyLayers: MoneyLayer[];
  rail: 'INTERNAL' | 'CHAIN138' | 'SWIFT' | 'RTGS';
  /** External SWIFT/HYBX beneficiary IBAN when rail is external */
  creditorIban?: string;
  beneficiaryName?: string;
  remittanceInfo?: string;
  currency?: string;
};

export type SettlementRecord = {
  settlementId: string;
  idempotencyKey: string;
  phase: SettlementPhase;
  request: ExternalTransferRequest;
  fineractJournalRef?: string;
  hybxPaymentId?: string;
  iso20022MessageId?: string;
  chainTxHash?: string;
  verbiageDocument?: string;
  errors: string[];
  createdAt: string;
  updatedAt: string;
};

export type MoneySupplySnapshot = {
  asOf: string;
  officeId: number;
  M0: { reserveOz?: string; gl1050: string; backingRatio: number };
  M1: { circulating: string; gl2000: string; gl2100: string; capMultiple: number };
  M2: { broadMoney: string; gl2200: string; metaFiatPending: string };
  metaFiatRealRail: { pendingSettlement: string; inFlightSwift: string };
};
