// Global Banking Identity Graph (GBIG) - Type Definitions

export enum IdentityLayer {
  SOVEREIGN = 'SOVEREIGN', // Layer 1 - Sovereign Identity Layer (SIL)
  INSTITUTIONAL = 'INSTITUTIONAL', // Layer 2 - Institutional Identity Layer (IIL)
  RETAIL = 'RETAIL', // Layer 3 - Retail & Individual Layer (RIL)
  CONTRACT = 'CONTRACT', // Layer 4 - Contract Identity Layer (CIL)
}

export enum IdentityType {
  SCB = 'SCB', // Sovereign Central Bank
  PRIVATE_BANK = 'PRIVATE_BANK',
  CBDC_WALLET_RETAIL = 'CBDC_WALLET_RETAIL',
  CBDC_WALLET_WHOLESALE = 'CBDC_WALLET_WHOLESALE',
  CBDC_WALLET_INSTITUTIONAL = 'CBDC_WALLET_INSTITUTIONAL',
  SMART_CONTRACT = 'SMART_CONTRACT',
  API_CREDENTIAL = 'API_CREDENTIAL',
  NODE = 'NODE',
  VALIDATOR = 'VALIDATOR',
  DEVICE = 'DEVICE',
}

export enum RelationshipType {
  AUTHORIZES = 'AUTHORIZES',
  ISSUES = 'ISSUES',
  EXECUTES_WITH = 'EXECUTES_WITH',
  OWNS = 'OWNS',
  CONTROLS = 'CONTROLS',
  VERIFIES = 'VERIFIES',
  TRUSTS = 'TRUSTS',
}

export enum KYCLevel {
  LEVEL_0 = 0, // No verification
  LEVEL_1 = 1, // Basic identity
  LEVEL_2 = 2, // Enhanced due diligence
  LEVEL_3 = 3, // Full verification with source of funds
  LEVEL_4 = 4, // Sovereign-grade verification
}

export interface IdentityNode {
  id: string;
  identityType: IdentityType;
  layer: IdentityLayer;
  sovereignBankId?: string;
  certificateHash?: string; // Root sovereign certificate hash
  masterKeyId?: string; // SCB master key ID
  hsmSignature?: string; // HSM-backed validation signature
  contractHashId?: string; // For smart contracts
  sovereignSignatoryList?: string[]; // For contracts
  executionPermissions?: string[];
  kycLevel: KYCLevel;
  trustScore: number; // Identity Trust Score (ITS)
  status: 'ACTIVE' | 'SUSPENDED' | 'REVOKED' | 'PENDING';
  createdAt: Date;
  updatedAt: Date;
  metadata?: Record<string, unknown>;
}

export interface IdentityEdge {
  id: string;
  fromNodeId: string;
  toNodeId: string;
  relationshipType: RelationshipType;
  riskScore?: number;
  authorizationLevel: number; // 0-100
  transactionVelocity?: {
    daily: number;
    weekly: number;
    monthly: number;
  };
  createdAt: Date;
  updatedAt: Date;
  metadata?: Record<string, unknown>;
}

export interface IdentityTrustScore {
  identityId: string;
  baseTrust: number;
  kycLevel: KYCLevel;
  behaviorScore: number;
  riskPenalties: number;
  totalScore: number; // ITS = base_trust + (KYC_level * 10) + behavior_score - risk_penalties
  factors: {
    transactionHistory: number;
    amlFlags: number;
    fxRiskExposure: number;
    deviceSecurityPosture: number;
  };
  calculatedAt: Date;
}

export interface GBIGGraph {
  nodes: IdentityNode[];
  edges: IdentityEdge[];
}

export interface IdentityVerificationRequest {
  identityId: string;
  verificationType: 'KYC' | 'KYB' | 'SOVEREIGN' | 'CONTRACT';
  evidence: Record<string, unknown>;
}

export interface IdentityVerificationResult {
  identityId: string;
  verified: boolean;
  trustScore: number;
  verificationLevel: KYCLevel;
  issues?: string[];
}

