/**
 * Email Branding Configuration
 * 
 * Centralized configuration for email branding, logos, and company information
 * Customize this file to match your organization's branding
 */

import { EmailHeaderConfig, EmailFooterConfig } from './helpers';

const appDomain = process.env.APP_DOMAIN || 'royalenfield.com';

/**
 * Company Information
 */
export const CompanyInfo = {
  name: 'Royal Enfield',
  productName: 'RE Flow',  // Product name displayed in header
  website: `https://www.${appDomain}`,
  supportEmail: `support@${appDomain}`,

  // Logo configuration for email headers
  logo: {
    url: `https://www.${appDomain}/content/dam/RE-Platform-Revamp/re-revamp-commons/logo.webp`,
    alt: 'Royal Enfield Logo',
    width: 220,   // Logo width in pixels (wider for better visibility)
    height: 65,   // Logo height in pixels (proportional ratio ~3.4:1)
    enabled: true // Logo enabled - displays directly on black background
  }
};

/**
 * Email Footer Configuration
 * Used across all email templates
 */
export function getDefaultFooterConfig(): EmailFooterConfig {
  return {
    companyName: CompanyInfo.name,
    companyWebsite: CompanyInfo.website,
    supportEmail: CompanyInfo.supportEmail,
    additionalLinks: [
      { text: 'Help Center', url: `${CompanyInfo.website}/help` },
      { text: 'Privacy Policy', url: `${CompanyInfo.website}/privacy` },
      { text: 'Terms of Service', url: `${CompanyInfo.website}/terms` }
    ]
  };
}

/**
 * Get Email Header with Logo and Product Name (if enabled in branding config)
 * 
 * Usage:
 * ${getEmailHeader(getBrandedHeader({ 
 *   title: 'Request Approved',
 *   ...HeaderStyles.success 
 * }))}
 */
export function getBrandedHeader(config: Omit<EmailHeaderConfig, 'logoUrl' | 'logoAlt' | 'logoWidth' | 'logoHeight' | 'productName'>): EmailHeaderConfig {
  return {
    ...config,
    productName: CompanyInfo.productName,
    ...(CompanyInfo.logo.enabled && {
      logoUrl: CompanyInfo.logo.url,
      logoAlt: CompanyInfo.logo.alt,
      logoWidth: CompanyInfo.logo.width,
      logoHeight: CompanyInfo.logo.height
    })
  };
}

/**
 * Custom Color Schemes (Optional)
 * Override default header colors for specific templates
 */
export const CustomHeaderStyles = {
  // You can override or add custom styles here
  // Example:
  // brandPrimary: {
  //   gradientFrom: '#FF0000',
  //   gradientTo: '#AA0000'
  // }
};

/**
 * Generate view details link for emails
 * 
 * @param requestNumber - Request number (e.g., REQ-2025-12-0013)
 * @param frontendUrl - Frontend base URL (from process.env.FRONTEND_URL in your service)
 * @returns Full URL to request detail page
 * 
 * Usage in email service:
 * const link = getViewDetailsLink('REQ-2025-12-0013', process.env.FRONTEND_URL);
 * 
 * Result: https://workflow.royalenfield.com/request/REQ-2025-12-0013
 */
export function getViewDetailsLink(requestNumber: string, frontendUrl: string): string {
  return `${frontendUrl}/request/${requestNumber}`;
}

/**
 * NOTE: To use environment variables, import this in your service file
 * and override these values with process.env at runtime:
 * 
 * Example in your email service:
 * 
 * import { CompanyInfo, BaseURL } from './emailtemplates/branding.config';
 * 
 * // Override with environment variables
 * CompanyInfo.name = process.env.COMPANY_NAME || CompanyInfo.name;
 * BaseURL = process.env.BASE_URL || BaseURL;
 */
