/**
 * VNLH-VND SDK — Constants & Configuration
 * Hằng số hệ thống theo quy định NHNN và chuẩn ISO 20022/SWIFT
 */

// ─── BIC chính thức của NHNN ──────────────────────────────────────────────────
export const SBV_BIC            = 'SBVNVNVX';
export const NAPAS_BIC          = 'NAPAVNVX';
export const SBV_GOV_CHAIN_RPC  = process.env.GOV_CHAIN_RPC    ?? 'http://gov-chain.sbv.gov.vn:8545';
export const SBV_GOV_CHAIN_ON   = process.env.GOV_CHAIN_ENABLED === 'true';

// ─── SWIFT API Gateway endpoints ─────────────────────────────────────────────
export const SWIFT_GW_LIVE      = 'https://api.swiftnet.sipn.swift.com';
export const SWIFT_GW_PILOT     = 'https://api-test.swiftnet.sipn.swift.com';
export const SWIFT_GW_SANDBOX   = 'https://sandbox.swift.com';
export const SWIFT_OAUTH_PATH   = 'oauth2/v1/token';
export const SWIFT_OAUTH_AUD_LIVE   = 'api.swiftnet.sipn.swift.com/oauth2/v1/token';
export const SWIFT_OAUTH_AUD_PILOT  = 'api-test.swiftnet.sipn.swift.com/oauth2/v1/token';

// ─── ISO 20022 Namespaces ─────────────────────────────────────────────────────
export const NS = {
  HEAD001: 'urn:iso:std:iso:20022:tech:xsd:head.001.001.03',
  PACS008: 'urn:iso:std:iso:20022:tech:xsd:pacs.008.001.09',
  PACS009: 'urn:iso:std:iso:20022:tech:xsd:pacs.009.001.09',
  PACS002: 'urn:iso:std:iso:20022:tech:xsd:pacs.002.001.11',
  PAIN001: 'urn:iso:std:iso:20022:tech:xsd:pain.001.001.09',
  PAIN002: 'urn:iso:std:iso:20022:tech:xsd:pain.002.001.11',
  CAMT053: 'urn:iso:std:iso:20022:tech:xsd:camt.053.001.10',
  CAMT054: 'urn:iso:std:iso:20022:tech:xsd:camt.054.001.10',
  CAMT056: 'urn:iso:std:iso:20022:tech:xsd:camt.056.001.10',
  AUTH001: 'urn:iso:std:iso:20022:tech:xsd:auth.001.001.02',
  AUTH002: 'urn:iso:std:iso:20022:tech:xsd:auth.002.001.02',
  AUTH018: 'urn:iso:std:iso:20022:tech:xsd:auth.018.001.04',
} as const;

// ─── AML/CFT Ngưỡng kiểm soát (VND) ─────────────────────────────────────────
// Theo Nghị định 116/2013/NĐ-CP và Thông tư 09/2023/TT-NHNN
export const AML_THRESHOLD = {
  /** Ngưỡng giao dịch tiền mặt phải báo cáo (200 triệu VND) */
  CASH_REPORT_VND:        200_000_000,
  /** Ngưỡng chuyển khoản điện tử phải EDD (500 triệu VND) */
  WIRE_EDD_VND:           500_000_000,
  /** Ngưỡng chuyển vốn xuyên biên giới phải báo cáo (1 tỷ VND) */
  CROSS_BORDER_REPORT_VND: 1_000_000_000,
  /** Ngưỡng bắt buộc Gov-Chain anchor (100 triệu VND) */
  GOV_CHAIN_ANCHOR_VND:    100_000_000,
} as const;

// ─── FX Control — Nghị định 70/2014/NĐ-CP ────────────────────────────────────
export const FX_CONTROL = {
  /** Tổ chức tín dụng phải báo cáo NHNN khi mua/bán ngoại tệ > ngưỡng này (USD) */
  REPORT_THRESHOLD_USD: 10_000,
  /** Cá nhân mang ngoại tệ tiền mặt > ngưỡng này phải khai báo hải quan */
  CUSTOMS_DECLARATION_USD: 5_000,
} as const;

// ─── SWIFT gpi Tracker scopes ─────────────────────────────────────────────────
export const SWIFT_SCOPES = {
  GPI_TRACKER_FULL:   'swift.apitracker/FullViewer',
  GPI_TRACKER_UPDATE: 'swift.apitracker/Update',
  GPI_PREVAL:         'swift.preval/access_to_service',
  GPI_GCASE:          'swift.apitracker.gcase',
} as const;

// ─── Gov-Chain method IDs ─────────────────────────────────────────────────────
export const GOV_CHAIN_METHODS = {
  ANCHOR:       'sbv_anchor',
  QUERY_TX:     'sbv_getTransaction',
  QUERY_BLOCK:  'sbv_getBlock',
  LIST_ANCHORS: 'sbv_listAnchors',
} as const;

// ─── Routing downstream labels ────────────────────────────────────────────────
export const DOWNSTREAM = {
  NAPAS:      'NAPAS_DOMESTIC',
  MBRIDGE:    'ASEAN_MBRIDGE',
  SWIFT_LIVE: 'SWIFT_SIPN_LIVE',
  SUPERVISORY:'SBV_SUPERVISORY',
  ACCOUNT_MGT:'SBV_ACCOUNT_MGT',
  GOV:        'VNLH_GOV',
  CBDC:       'CBDC_PILOT',
} as const;

// ─── Timeout defaults (ms) ────────────────────────────────────────────────────
export const TIMEOUT = {
  GOV_CHAIN:     5_000,
  SWIFT_OAUTH:  15_000,
  KAFKA_PUBLISH: 3_000,
  HTTP_DEFAULT: 30_000,
} as const;

// ─── Message Definition ID prefixes ──────────────────────────────────────────
export const MSG_PREFIX = {
  PAIN: 'pain.',
  PACS: 'pacs.',
  CAMT: 'camt.',
  AUTH: 'auth.',
  HEAD: 'head.',
} as const;

// ─── Phiên bản SDK ────────────────────────────────────────────────────────────
export const SDK_VERSION = {
  VNLH_SDK:    '1.0.0',
  SWIFT_SDK:   '2.17.10-6',
  SECURITY_SDK:'2.17.5-6',
  ISO20022:    '2023',
} as const;
