/**
 * ISO-4217 compliant token symbol registry.
 * v0 symbols (cUSDT, cUSDC) are maintained on ChainID 138 only; the X designator is left out on 138.
 * X is used only for origin reference (e.g. bridged cWXUSDC). See docs/04-configuration/ISO4217_COMPLIANT_TOKEN_MATRIX.md
 */

export type AssetTypeChar = 'C' | 'T' | 'W';

export interface V1SymbolIdentity {
  iso: string;
  type: AssetTypeChar;
  originChain: string;
}

/** v0 symbol (Chain 138 only) → identity; originChain 'X' denotes 138 for reporting/bridged reference only */
export const V0_TO_V1_SYMBOL_MAP: Record<string, V1SymbolIdentity> = {
  cUSDT: { iso: 'USD', type: 'T', originChain: 'X' },
  cUSDC: { iso: 'USD', type: 'C', originChain: 'X' },
};

/** Financial chain designators: X = Chain 138 (origin only), A = Alltra. Chain 138 native symbols use v0 (no X). */
export const FIN_CHAIN_SET = ['X', 'A'] as const;
export type FinChainDesignator = (typeof FIN_CHAIN_SET)[number];

/** Supported ISO-4217 codes (3 letters). Extend via registry. */
export const ISO4217_SUPPORTED = [
  'USD',
  'EUR',
  'GBP',
  'JPY',
  'AUD',
  'CHF',
  'CAD',
  'CNY',
  'XAU',
] as const;
export type ISO4217Code = (typeof ISO4217_SUPPORTED)[number];

/** Valid type suffix for compliant symbols */
export const ASSET_TYPE_SET = ['C', 'T', 'W'] as const;

export function isFinChainDesignator(c: string): boolean {
  return (FIN_CHAIN_SET as readonly string[]).includes(c);
}

export function isISO4217Supported(code: string): boolean {
  return (ISO4217_SUPPORTED as readonly string[]).includes(code);
}

export function isAssetTypeChar(c: string): boolean {
  return (ASSET_TYPE_SET as readonly string[]).includes(c);
}

export function getV1IdentityForV0Symbol(v0Symbol: string): V1SymbolIdentity | undefined {
  return V0_TO_V1_SYMBOL_MAP[v0Symbol];
}
