/**
 * Credential test fixtures
 */

import { randomUUID } from 'crypto';

export interface TestCredential {
  id: string;
  subject: string;
  issuer: string;
  type: string[];
  credentialSubject: Record<string, unknown>;
  issuanceDate: string;
  expirationDate?: string;
  proof: {
    type: string;
    cryptosuite: string;
    proofPurpose: string;
    verificationMethod: string;
    created: string;
    signature: string;
  };
}

/**
 * Create a test verifiable credential
 */
export function createTestCredential(overrides?: Partial<TestCredential>): TestCredential {
  const now = new Date();
  const expirationDate = new Date(now);
  expirationDate.setFullYear(expirationDate.getFullYear() + 1);
  
  return {
    id: randomUUID(),
    subject: `did:web:example.com:user:${randomUUID()}`,
    issuer: 'did:web:theorder.org',
    type: ['VerifiableCredential', 'TestCredential'],
    credentialSubject: {
      id: `did:web:example.com:user:${randomUUID()}`,
      name: 'Test User',
      email: 'test@example.com',
    },
    issuanceDate: now.toISOString(),
    expirationDate: expirationDate.toISOString(),
    proof: {
      type: 'DataIntegrityProof',
      cryptosuite: 'eddsa-rpr-2020',
      proofPurpose: 'assertionMethod',
      verificationMethod: 'did:web:theorder.org#key-1',
      created: now.toISOString(),
      signature: 'test-signature-' + randomUUID(),
    },
    ...overrides,
  };
}

/**
 * Create a test judicial credential
 */
export function createTestJudicialCredential(
  role: 'Registrar' | 'Judge' | 'ProvostMarshal',
  overrides?: Partial<TestCredential>
): TestCredential {
  return createTestCredential({
    type: ['VerifiableCredential', 'JudicialCredential', role],
    credentialSubject: {
      id: `did:web:example.com:judicial:${randomUUID()}`,
      role,
      appointmentDate: new Date().toISOString(),
      termEndDate: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).toISOString(),
      jurisdiction: 'International',
    },
    ...overrides,
  });
}

/**
 * Create a test financial credential
 */
export function createTestFinancialCredential(
  role: 'ComptrollerGeneral' | 'MonetaryComplianceOfficer' | 'CustodianOfDigitalAssets' | 'FinancialAuditor',
  overrides?: Partial<TestCredential>
): TestCredential {
  return createTestCredential({
    type: ['VerifiableCredential', 'FinancialRoleCredential', role],
    credentialSubject: {
      id: `did:web:example.com:financial:${randomUUID()}`,
      role,
      appointmentDate: new Date().toISOString(),
      termEndDate: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).toISOString(),
      department: 'Finance',
    },
    ...overrides,
  });
}

/**
 * Create a test eIDAS signature
 */
export function createTestEIDASSignature() {
  return {
    signature: 'test-eidas-signature-' + randomUUID(),
    certificate: '-----BEGIN CERTIFICATE-----\nTEST CERTIFICATE\n-----END CERTIFICATE-----',
    timestamp: new Date(),
  };
}

/**
 * Create a test DID document
 */
export function createTestDIDDocument(did: string = `did:web:example.com:${randomUUID()}`) {
  return {
    id: did,
    '@context': ['https://www.w3.org/ns/did/v1'],
    verificationMethod: [
      {
        id: `${did}#keys-1`,
        type: 'Ed25519VerificationKey2020',
        controller: did,
        publicKeyMultibase: 'z' + 'A'.repeat(64), // Simulated multibase key
      },
    ],
    authentication: [`${did}#keys-1`],
  };
}

