// Seed Vault Marketplace Offering
// Adds Vault 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 Vault marketplace offering...');

  const offeringId = 'VAULT-VIRTUAL-VAULT';
  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: 'Virtual Vault Service',
        description: 'Enterprise-grade secrets management with HashiCorp Vault. Create isolated virtual vaults on our high-availability Vault cluster for secure storage and management of secrets, API keys, certificates, and sensitive configuration data.',
        capacityTier: 0, // Available to all tiers
        institutionalType: 'all',
        pricingModel: 'subscription',
        basePrice: 500.00, // Monthly base price
        currency: 'USD',
        features: {
          secretsManagement: true,
          encryptionAtRest: true,
          encryptionInTransit: true,
          highAvailability: true,
          automaticBackups: true,
          auditLogging: true,
          apiAccess: true,
          cliAccess: true,
          sdkSupport: ['nodejs', 'python', 'java', 'go', 'dotnet'],
          integrations: ['kubernetes', 'terraform', 'ansible', 'jenkins'],
        },
        technicalSpecs: {
          vaultVersion: '1.21.2',
          clusterType: 'Raft HA',
          nodeCount: 3,
          redundancy: 'Full',
          storageBackend: 'Raft',
          apiEndpoints: [
            'http://192.168.11.200:8200',
            'http://192.168.11.215:8200',
            'http://192.168.11.202:8200',
          ],
          authentication: ['AppRole', 'Token', 'LDAP', 'OIDC'],
          encryption: 'AES-256-GCM',
          compliance: ['SOC 2', 'ISO 27001', 'GDPR'],
          sla: '99.9%',
          backupFrequency: 'Daily',
          retention: '30 days',
        },
        legalFramework: {
          serviceAgreement: 'Virtual Vault Service Agreement',
          dataProcessing: 'GDPR Compliant',
          jurisdiction: 'International',
        },
        regulatoryPosition: {
          compliance: 'Enterprise-grade security and compliance',
          certifications: ['SOC 2', 'ISO 27001'],
          dataResidency: 'Configurable',
        },
        documents: {
          serviceAgreement: '/documents/vault-service-agreement.pdf',
          technicalDocumentation: '/documents/vault-technical-specs.pdf',
          apiDocumentation: '/documents/vault-api-docs.pdf',
          integrationGuide: '/documents/vault-integration-guide.pdf',
        },
        status: 'active',
        displayOrder: 10,
        updatedAt: new Date(),
      },
    });

    console.log(`✅ Offering ${offeringId} updated successfully`);
  } else {
    await prisma.iruOffering.create({
      data: {
        id: uuidv4(),
        offeringId,
        name: 'Virtual Vault Service',
        description: 'Enterprise-grade secrets management with HashiCorp Vault. Create isolated virtual vaults on our high-availability Vault cluster for secure storage and management of secrets, API keys, certificates, and sensitive configuration data.',
        capacityTier: 0, // Available to all tiers
        institutionalType: 'all',
        pricingModel: 'subscription',
        basePrice: 500.00, // Monthly base price
        currency: 'USD',
        features: {
          secretsManagement: true,
          encryptionAtRest: true,
          encryptionInTransit: true,
          highAvailability: true,
          automaticBackups: true,
          auditLogging: true,
          apiAccess: true,
          cliAccess: true,
          sdkSupport: ['nodejs', 'python', 'java', 'go', 'dotnet'],
          integrations: ['kubernetes', 'terraform', 'ansible', 'jenkins'],
        },
        technicalSpecs: {
          vaultVersion: '1.21.2',
          clusterType: 'Raft HA',
          nodeCount: 3,
          redundancy: 'Full',
          storageBackend: 'Raft',
          apiEndpoints: [
            'http://192.168.11.200:8200',
            'http://192.168.11.215:8200',
            'http://192.168.11.202:8200',
          ],
          authentication: ['AppRole', 'Token', 'LDAP', 'OIDC'],
          encryption: 'AES-256-GCM',
          compliance: ['SOC 2', 'ISO 27001', 'GDPR'],
          sla: '99.9%',
          backupFrequency: 'Daily',
          retention: '30 days',
        },
        legalFramework: {
          serviceAgreement: 'Virtual Vault Service Agreement',
          dataProcessing: 'GDPR Compliant',
          jurisdiction: 'International',
        },
        regulatoryPosition: {
          compliance: 'Enterprise-grade security and compliance',
          certifications: ['SOC 2', 'ISO 27001'],
          dataResidency: 'Configurable',
        },
        documents: {
          serviceAgreement: '/documents/vault-service-agreement.pdf',
          technicalDocumentation: '/documents/vault-technical-specs.pdf',
          apiDocumentation: '/documents/vault-api-docs.pdf',
          integrationGuide: '/documents/vault-integration-guide.pdf',
        },
        status: 'active',
        displayOrder: 10,
        createdAt: new Date(),
        updatedAt: new Date(),
      },
    });

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

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