// Seed AS4 Settlement Marketplace Offering
// Adds AS4 Settlement Master Service to Sankofa Phoenix Marketplace

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

const prisma = new PrismaClient();

async function main() {
  console.log('Seeding AS4 Settlement Marketplace Offering...');

  // Check if offering already exists
  const existing = await prisma.iruOffering.findUnique({
    where: { offeringId: 'AS4-SETTLEMENT-MASTER' },
  });

  if (existing) {
    console.log('AS4 Settlement offering already exists, skipping...');
    return;
  }

  // Create offering
  const offering = await prisma.iruOffering.create({
    data: {
      id: uuidv4(),
      offeringId: 'AS4-SETTLEMENT-MASTER',
      name: 'AS4 Settlement Master Service',
      description:
        'Final settlement institution providing SWIFT-FIN equivalent instruction and confirmation flows (MT202/MT910 semantics) over a custom AS4 gateway, with settlement posting on the DBIS ledger (ChainID 138).',
      capacityTier: 1, // Central Banks and Settlement Banks
      institutionalType: 'SettlementBank',
      pricingModel: 'Hybrid', // Subscription + Usage-based
      basePrice: 10000, // $10,000/month base
      currency: 'USD',
      features: {
        messageTypes: ['DBIS.SI.202', 'DBIS.SI.202COV', 'DBIS.AD.900', 'DBIS.AD.910'],
        capabilities: [
          'AS4 Gateway',
          'Settlement Core',
          'Member Directory',
          'Compliance Gates',
          'Ledger Integration',
          'ChainID 138 Anchoring',
        ],
        supportedCurrencies: ['USD', 'EUR', 'GBP', 'XAU', 'XAG'],
        finality: 'IMMEDIATE',
        availability: '99.9%',
      },
      technicalSpecs: {
        as4Version: 'ebMS3/AS4',
        ledgerMode: 'HYBRID',
        chainId: 138,
        messageFormat: 'JSON',
        signingAlgorithm: 'RSA-SHA256',
        encryptionAlgorithm: 'AES-256-GCM',
        tlsVersion: '1.3',
      },
      legalFramework: {
        rulebook: 'DBIS AS4 Settlement Member Rulebook v1.0',
        compliance: ['AML/CTF', 'Sanctions Screening', 'KYC/KYB'],
        audit: 'IMMUTABLE_WORM_STORAGE',
      },
      regulatoryPosition: {
        status: 'REGULATED',
        jurisdictions: ['GLOBAL'],
        licensing: 'REQUIRED',
      },
      documents: {
        rulebook: '/docs/settlement/as4/MEMBER_RULEBOOK_V1.md',
        pkiModel: '/docs/settlement/as4/PKI_CA_MODEL.md',
        directorySpec: '/docs/settlement/as4/DIRECTORY_SERVICE_SPEC.md',
        threatModel: '/docs/settlement/as4/THREAT_MODEL_CONTROL_CATALOG.md',
      },
      status: 'active',
      displayOrder: 10,
    },
  });

  console.log('AS4 Settlement Marketplace Offering created:', offering.offeringId);
}

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