// Global Regulatory Harmonization Suite (GRHS) - Main Service

import { regulatoryEquivalenceService } from './regulatory-equivalence.service';
import { monetaryHarmonizationService } from './monetary-harmonization.service';
import { legalHarmonizationService } from './legal-harmonization.service';
import { complianceHarmonizationService } from './compliance-harmonization.service';
import { tradeHarmonizationService } from './trade-harmonization.service';
import { HarmonizationPillar, RegulatoryEquivalenceScore } from './types';
import { logger } from '@/infrastructure/monitoring/logger';

export class GRHSService {
  /**
   * Initialize GRHS with default rules
   */
  async initialize(): Promise<void> {
    logger.info('Initializing GRHS with default rules');

    await monetaryHarmonizationService.initializeDefaultRules();
    await legalHarmonizationService.initializeDefaultRules();
    await complianceHarmonizationService.initializeDefaultRules();
    await tradeHarmonizationService.initializeDefaultRules();

    logger.info('GRHS initialization completed');
  }

  /**
   * Calculate REP score for sovereign
   */
  async calculateREPScore(sovereignBankId: string): Promise<RegulatoryEquivalenceScore> {
    return regulatoryEquivalenceService.calculateREPScore(sovereignBankId);
  }

  /**
   * Assess compliance across all pillars
   */
  async assessCompliance(sovereignBankId: string): Promise<Record<HarmonizationPillar, number>> {
    const [monetary, legal, compliance, trade] = await Promise.all([
      monetaryHarmonizationService.assessCompliance(sovereignBankId),
      legalHarmonizationService.assessCompliance(sovereignBankId),
      complianceHarmonizationService.assessCompliance(sovereignBankId),
      tradeHarmonizationService.assessCompliance(sovereignBankId),
    ]);

    return {
      [HarmonizationPillar.MONETARY]: monetary,
      [HarmonizationPillar.LEGAL]: legal,
      [HarmonizationPillar.COMPLIANCE]: compliance,
      [HarmonizationPillar.TRADE]: trade,
    };
  }

  /**
   * Grant fast-track privileges
   */
  async grantFastTrackPrivileges(sovereignBankId: string): Promise<void> {
    return regulatoryEquivalenceService.grantFastTrackPrivileges(sovereignBankId);
  }

  /**
   * Check fast-track privilege
   */
  async hasFastTrackPrivilege(
    sovereignBankId: string,
    privilegeType: 'SETTLEMENT' | 'LIQUIDITY' | 'OVERSIGHT'
  ): Promise<boolean> {
    return regulatoryEquivalenceService.hasFastTrackPrivilege(sovereignBankId, privilegeType);
  }
}

export const grhsService = new GRHSService();

