// OMNL White-Label Instance Setup

import prisma from '@/shared/database/prisma';
import { sovereignIdentityFabric } from '@/sovereign/identity/sovereign-identity-fabric.service';
import { SOVEREIGN_CODES } from '@/shared/constants';
import { IdentityType } from '@/shared/types';

export class OmnlService {
  /**
   * Initialize OMNL sovereign instance
   */
  async initializeOmnlInstance(): Promise<void> {
    // Create OMNL sovereign bank record
    const omnlBank = await prisma.sovereignBank.upsert({
      where: { sovereignCode: SOVEREIGN_CODES.OMNL },
      update: {},
      create: {
        sovereignCode: SOVEREIGN_CODES.OMNL,
        name: 'OMNL Central Bank',
        bic: 'OMNLXXXX',
        status: 'active',
      },
    });

    // Create Root Sovereign Identity
    await sovereignIdentityFabric.createRootSovereignIdentity(
      omnlBank.id,
      SOVEREIGN_CODES.OMNL
    );

    // Create tiered identities
    await sovereignIdentityFabric.createTieredIdentity(
      omnlBank.id,
      IdentityType.TREASURY,
      SOVEREIGN_CODES.OMNL
    );
    await sovereignIdentityFabric.createTieredIdentity(
      omnlBank.id,
      IdentityType.CBDC,
      SOVEREIGN_CODES.OMNL
    );
    await sovereignIdentityFabric.createTieredIdentity(
      omnlBank.id,
      IdentityType.SETTLEMENT,
      SOVEREIGN_CODES.OMNL
    );
    await sovereignIdentityFabric.createTieredIdentity(
      omnlBank.id,
      IdentityType.API,
      SOVEREIGN_CODES.OMNL
    );
  }
}

export const omnlService = new OmnlService();

