/**
 * Example Usage of Landing Page Generator
 * Run this to test page generation
 */

import { 
  generateLandingPages, 
  createLandingPageConfig,
  deployLocal 
} from './index';
import type { BusinessInfo, CampaignInfo } from '../types';

// Mock data for testing
const mockBusiness: BusinessInfo = {
  businessName: 'Acme Fitness Studio',
  businessType: 'Limited Liability Corporation',
  businessIndustry: 'HEALTHCARE',
  registrationIdentifier: 'EIN',
  registrationNumber: '12-3456789',
  websiteUrl: 'https://acmefitness.com',
  socialMediaUrls: [
    'https://facebook.com/acmefitness',
    'https://instagram.com/acmefitness'
  ],
  businessIdentity: 'direct_customer',
  regionsOfOperation: ['USA_AND_CANADA'],
  companyType: 'private',
  skipAutoSecVet: false
};

const mockCampaign: CampaignInfo = {
  useCase: 'ACCOUNT_NOTIFICATION',
  description: 'Class schedule updates, booking confirmations, and membership reminders for Acme Fitness Studio members.',
  sampleMessages: [
    'Your yoga class tomorrow at 9 AM is confirmed! Reply CANCEL to cancel.',
    'Reminder: Your monthly membership payment of $49 is due in 3 days.',
    'New HIIT class added this Saturday at 10 AM. Book now!'
  ],
  messageFlow: 'Users opt in by texting START to our number or via our website opt-in form. They receive a confirmation message immediately.',
  optInType: 'WEB_FORM',
  optInMessage: 'Welcome to Acme Fitness! You\'re now subscribed to class updates and reminders. Reply STOP to opt out anytime.',
  optOutMessage: 'You\'ve been unsubscribed from Acme Fitness messages. Reply START to re-subscribe.',
  helpMessage: 'Acme Fitness: Get class updates and reminders. Msg frequency varies. Msg&data rates may apply. Reply STOP to quit. Help: support@acmefitness.com',
  optInKeywords: ['START', 'SUBSCRIBE', 'JOIN'],
  optOutKeywords: ['STOP', 'END', 'UNSUBSCRIBE'],
  helpKeywords: ['HELP', 'INFO'],
  hasEmbeddedLinks: true,
  hasEmbeddedPhone: false
};

/**
 * Generate and preview pages
 */
async function generateExample() {
  console.log('🎨 Generating landing pages for Acme Fitness Studio...\n');
  
  // 1. Create configuration
  const config = createLandingPageConfig(
    mockBusiness,
    mockCampaign,
    'support@acmefitness.com',
    '+15551234567',
    'https://comply.acmefitness.com',
    {
      brandColor: '#FF6B35',  // Orange for fitness brand
      messageFrequency: 'up to 8 messages per month'
    }
  );
  
  console.log('✅ Configuration created:');
  console.log(`   Business: ${config.businessName}`);
  console.log(`   Slug: ${config.businessSlug}`);
  console.log(`   Brand Color: ${config.brandColor}`);
  console.log(`   Message Frequency: ${config.messageFrequency}\n`);
  
  // 2. Generate pages
  const pages = generateLandingPages(config, mockCampaign, mockBusiness);
  
  console.log('✅ Pages generated:');
  console.log(`   Opt-in HTML: ${(pages.optInHtml.length / 1024).toFixed(1)} KB`);
  console.log(`   Privacy Policy: ${(pages.privacyPolicyHtml.length / 1024).toFixed(1)} KB`);
  console.log(`   Terms: ${(pages.termsHtml.length / 1024).toFixed(1)} KB\n`);
  
  // 3. Deploy locally (optional - uncomment to test)
  // const result = await deployLocal(pages, {
  //   publicDir: './test-output',
  //   baseUrl: 'http://localhost:3000'
  // });
  // 
  // console.log('🚀 Deployed to:');
  // console.log(`   Opt-in: ${result.optInUrl}`);
  // console.log(`   Privacy: ${result.privacyPolicyUrl}`);
  // console.log(`   Terms: ${result.termsUrl}`);
  
  console.log('✨ Generation complete!\n');
  console.log('To deploy:');
  console.log('  await deployLocal(pages, { publicDir: "./public", baseUrl: "https://your-domain.com" });');
  console.log('  await deployVercel(pages, { apiToken: process.env.VERCEL_TOKEN! });');
  
  return pages;
}

// Run if executed directly
if (require.main === module) {
  generateExample()
    .then(() => console.log('\n✅ Example completed successfully'))
    .catch(err => {
      console.error('\n❌ Error:', err);
      process.exit(1);
    });
}

export { generateExample };
