// Seed DBIS Core Banking Private Offering
// Adds DBIS Core Banking System as a private offering in Phoenix Portal

import { PrismaClient } from '@prisma/client';
import { v4 as uuidv4 } from 'uuid';

const prisma = new PrismaClient();

async function main() {
  console.log('Seeding DBIS Core Banking private offering...');

  const offeringId = 'DBIS-CORE-BANKING-PRIVATE';
  const existingOffering = await prisma.iruOffering.findUnique({
    where: { offeringId },
  });

  if (existingOffering) {
    console.log(`Offering ${offeringId} already exists. Updating...`);
    
    await prisma.iruOffering.update({
      where: { offeringId },
      data: {
        name: 'DBIS Core Banking System',
        description: 'Sovereign-grade financial infrastructure for the Digital Bank of International Settlements and 33 Sovereign Central Banks. Complete core banking system with neural consensus engine, global quantum ledger, autonomous regulatory intelligence, and sovereign AI risk engine.',
        capacityTier: 1, // Tier 1: Central Banks only
        institutionalType: 'central_bank', // Private offering for central banks
        pricingModel: 'private', // Private offering, not publicly listed
        basePrice: null, // Pricing negotiated privately
        currency: 'USD',
        features: {
          coreBanking: true,
          neuralConsensusEngine: true,
          globalQuantumLedger: true,
          autonomousRegulatoryIntelligence: true,
          sovereignAIRiskEngine: true,
          sovereignSettlementNodes: true,
          cbdcSystem: true,
          globalSettlementSystem: true,
          instantSettlementNetwork: true,
          fxEngine: true,
          complianceAML: true,
          treasuryManagement: true,
          identityGraph: true,
          quantumResistant: true,
          multiAssetSupport: true,
          crossBorderSettlement: true,
          iso20022: true,
          hsmIntegration: true,
        },
        technicalSpecs: {
          systemType: 'Core Banking System',
          architecture: 'Sovereign-grade financial infrastructure',
          targetUsers: '33 Sovereign Central Banks',
          consensus: 'Neural Consensus Engine (NCE)',
          ledger: 'Global Quantum Ledger (GQL)',
          security: 'Quantum-resistant with XMSS/SPHINCS+ signatures',
          compliance: 'Autonomous Regulatory Intelligence (ARI)',
          riskManagement: 'Sovereign AI Risk Engine (SARE)',
          settlement: 'Global Settlement System (GSS)',
          payments: 'Instant Settlement Network (ISN)',
          cbdc: 'Full CBDC issuance and management',
          integration: 'ISO 20022, SWIFT, ACH, HSM',
          scalability: 'Multi-sovereign, multi-asset',
          availability: '99.99% uptime SLA',
        },
        legalFramework: {
          serviceAgreement: 'DBIS IRU Participation Agreement',
          dataProcessing: 'Sovereign-grade data protection',
          jurisdiction: 'Multi-sovereign',
          compliance: 'Regulatory compliance per jurisdiction',
        },
        regulatoryPosition: {
          compliance: 'Full regulatory compliance framework',
          certifications: ['ISO 27001', 'SOC 2 Type II', 'PCI DSS'],
          dataResidency: 'Sovereign-specific',
          regulatoryIntelligence: 'Autonomous regulatory compliance',
        },
        documents: {
          serviceAgreement: '/documents/dbis-core-banking-agreement.pdf',
          technicalDocumentation: '/documents/dbis-architecture-atlas.pdf',
          apiDocumentation: '/documents/dbis-api-guide.pdf',
          integrationGuide: '/documents/dbis-integration-guide.pdf',
          legalFramework: '/legal/README.md',
        },
        status: 'active',
        displayOrder: 1, // Top priority for private offerings
        updatedAt: new Date(),
      },
    });

    console.log(`✅ Offering ${offeringId} updated successfully`);
  } else {
    await prisma.iruOffering.create({
      data: {
        id: uuidv4(),
        offeringId,
        name: 'DBIS Core Banking System',
        description: 'Sovereign-grade financial infrastructure for the Digital Bank of International Settlements and 33 Sovereign Central Banks. Complete core banking system with neural consensus engine, global quantum ledger, autonomous regulatory intelligence, and sovereign AI risk engine.',
        capacityTier: 1, // Tier 1: Central Banks only
        institutionalType: 'central_bank', // Private offering for central banks
        pricingModel: 'private', // Private offering, not publicly listed
        basePrice: null, // Pricing negotiated privately
        currency: 'USD',
        features: {
          coreBanking: true,
          neuralConsensusEngine: true,
          globalQuantumLedger: true,
          autonomousRegulatoryIntelligence: true,
          sovereignAIRiskEngine: true,
          sovereignSettlementNodes: true,
          cbdcSystem: true,
          globalSettlementSystem: true,
          instantSettlementNetwork: true,
          fxEngine: true,
          complianceAML: true,
          treasuryManagement: true,
          identityGraph: true,
          quantumResistant: true,
          multiAssetSupport: true,
          crossBorderSettlement: true,
          iso20022: true,
          hsmIntegration: true,
        },
        technicalSpecs: {
          systemType: 'Core Banking System',
          architecture: 'Sovereign-grade financial infrastructure',
          targetUsers: '33 Sovereign Central Banks',
          consensus: 'Neural Consensus Engine (NCE)',
          ledger: 'Global Quantum Ledger (GQL)',
          security: 'Quantum-resistant with XMSS/SPHINCS+ signatures',
          compliance: 'Autonomous Regulatory Intelligence (ARI)',
          riskManagement: 'Sovereign AI Risk Engine (SARE)',
          settlement: 'Global Settlement System (GSS)',
          payments: 'Instant Settlement Network (ISN)',
          cbdc: 'Full CBDC issuance and management',
          integration: 'ISO 20022, SWIFT, ACH, HSM',
          scalability: 'Multi-sovereign, multi-asset',
          availability: '99.99% uptime SLA',
        },
        legalFramework: {
          serviceAgreement: 'DBIS IRU Participation Agreement',
          dataProcessing: 'Sovereign-grade data protection',
          jurisdiction: 'Multi-sovereign',
          compliance: 'Regulatory compliance per jurisdiction',
        },
        regulatoryPosition: {
          compliance: 'Full regulatory compliance framework',
          certifications: ['ISO 27001', 'SOC 2 Type II', 'PCI DSS'],
          dataResidency: 'Sovereign-specific',
          regulatoryIntelligence: 'Autonomous regulatory compliance',
        },
        documents: {
          serviceAgreement: '/documents/dbis-core-banking-agreement.pdf',
          technicalDocumentation: '/documents/dbis-architecture-atlas.pdf',
          apiDocumentation: '/documents/dbis-api-guide.pdf',
          integrationGuide: '/documents/dbis-integration-guide.pdf',
          legalFramework: '/legal/README.md',
        },
        status: 'active',
        displayOrder: 1, // Top priority for private offerings
        createdAt: new Date(),
        updatedAt: new Date(),
      },
    });

    console.log(`✅ Offering ${offeringId} created successfully`);
  }

  console.log('\n📋 Offering Details:');
  console.log(`   Offering ID: ${offeringId}`);
  console.log(`   Name: DBIS Core Banking System`);
  console.log(`   Type: Private Offering (Central Banks Only)`);
  console.log(`   Capacity Tier: 1 (Central Banks)`);
  console.log(`   Status: Active`);
  console.log(`   Display Order: 1 (Top Priority)`);
}

main()
  .catch((e) => {
    console.error('Error seeding DBIS Core Banking offering:', e);
    process.exit(1);
  })
  .finally(async () => {
    await prisma.$disconnect();
  });
