import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';

describe('whmcs phase e/f contract', () => {
  it('documents reconciliation, events and usage routes', () => {
    const whmcsSource = readFileSync(
      join(process.cwd(), 'src', 'integrations/whmcs/whmcs-integration.controller.ts'),
      'utf8',
    );
    assert.ok(whmcsSource.includes("'accounts'"));
    assert.ok(whmcsSource.includes("'services/import'"));
    assert.ok(whmcsSource.includes("'reconcile'"));
    assert.ok(whmcsSource.includes("'services/:externalServiceId/reconcile'"));
    assert.ok(whmcsSource.includes("'events'"));
    assert.ok(whmcsSource.includes("'events/ack'"));
    assert.ok(whmcsSource.includes("'services/:externalServiceId/usage'"));
    assert.ok(whmcsSource.includes("'services/:externalServiceId/usage/adjustments'"));

    const reconcileSource = readFileSync(
      join(process.cwd(), 'src', 'integrations/whmcs/whmcs-reconciliation.service.ts'),
      'utf8',
    );
    assert.ok(reconcileSource.includes('listAccounts'));
    assert.ok(reconcileSource.includes('importService'));
    assert.ok(reconcileSource.includes('reconcileInstallation'));

    const usageSource = readFileSync(
      join(process.cwd(), 'src', 'integrations/whmcs/whmcs-usage.service.ts'),
      'utf8',
    );
    assert.ok(usageSource.includes('runtime_minutes'));
    assert.ok(usageSource.includes('createAdjustment'));
  });

  it('documents WHMCS PHP ListAccounts and usage hooks', () => {
    const phpSource = readFileSync(
      join(process.cwd(), '..', '..', 'integrations/whmcs/modules/servers/hexagamecloud/hexagamecloud.php'),
      'utf8',
    );
    assert.ok(phpSource.includes('hexagamecloud_ListAccounts'));
    assert.ok(phpSource.includes('hexagamecloud_MetricProvider'));
    assert.ok(phpSource.includes('hexagamecloud_UsageUpdate'));
  });
});
