/**
 * E2E Tests for Enhanced Email Generator
 * Generated by Bangstack
 */

import * as fs from 'fs';
import '../generators/index';
import * as path from 'path';
import { GenerationOrchestrator } from '../generators/generation-orchestrator';
import { Workflow } from '../types/workflow';

describe('Enhanced Email E2E Tests', () => {
  const testOutputDir = path.join(__dirname, '../../.e2e-output/enhanced-email');

  beforeAll(() => {
    if (fs.existsSync(testOutputDir)) {
      fs.rmSync(testOutputDir, { recursive: true, force: true });
    }
  });

  afterAll(() => {
    if (fs.existsSync(testOutputDir)) {
      fs.rmSync(testOutputDir, { recursive: true, force: true });
    }
  });

  it('should generate complete email infrastructure', async () => {
    const workflow: Workflow = {
      workflow: {
        id: 'test-email',
        version: '1.0.0',
        name: 'Test Email',
        description: 'Testing email',
      },
      stack: {},
      email: {
        provider: 'sendgrid',
        config: {
          from_email: 'noreply@example.com',
        },
        queue: {
          enabled: true,
        },
        templates: [
          {
            name: 'welcome',
            subject: 'Welcome!',
          },
        ],
      },
    };

    const orchestrator = new GenerationOrchestrator();
    const _result = await orchestrator.generate(workflow, { outputDirectory: testOutputDir, dryRun: false });

    // Verify config
    const configPath = path.join(testOutputDir, 'api/src/config/email.ts');
    expect(fs.existsSync(configPath)).toBe(true);

    // Verify service
    const servicePath = path.join(testOutputDir, 'api/src/services/email-service.ts');
    expect(fs.existsSync(servicePath)).toBe(true);

    // Verify provider
    const providerPath = path.join(testOutputDir, 'api/src/services/email-provider.ts');
    expect(fs.existsSync(providerPath)).toBe(true);

    // Verify queue
    const queuePath = path.join(testOutputDir, 'api/src/queues/email-queue.ts');
    expect(fs.existsSync(queuePath)).toBe(true);

    // Verify template
    const templatePath = path.join(testOutputDir, 'api/templates/email/welcome.html');
    expect(fs.existsSync(templatePath)).toBe(true);
  });
});
