from fastapi import APIRouter, HTTPException from pydantic import BaseModel, EmailStr from typing import Optional from app.services.email_service import EmailService router = APIRouter() class NewsletterSubscription(BaseModel): email: EmailStr name: Optional[str] = None class ContactForm(BaseModel): name: str email: EmailStr company: Optional[str] = None message: str phone: Optional[str] = None class SalesInquiry(BaseModel): name: str email: EmailStr company: str employees: str use_case: str message: Optional[str] = None @router.post("/newsletter/subscribe") async def subscribe_to_newsletter(subscription: NewsletterSubscription): email_service = EmailService() try: success = await email_service.send_newsletter_signup_confirmation(subscription.email) if success: return {"message": "Successfully subscribed to newsletter"} else: raise HTTPException(status_code=500, detail="Failed to send confirmation email") except Exception as e: raise HTTPException(status_code=500, detail=f"Error processing subscription: {str(e)}") @router.post("/contact") async def contact_form(contact: ContactForm): email_service = EmailService() try: # Send confirmation to user user_confirmation = await email_service.send_contact_confirmation( contact.email, contact.name ) # Send notification to admin admin_notification = await email_service.send_contact_notification( contact.name, contact.email, contact.company, contact.message ) if user_confirmation and admin_notification: return {"message": "Contact form submitted successfully"} else: raise HTTPException(status_code=500, detail="Failed to process contact form") except Exception as e: raise HTTPException(status_code=500, detail=f"Error processing contact form: {str(e)}") @router.post("/sales/inquiry") async def sales_inquiry(inquiry: SalesInquiry): email_service = EmailService() try: # Send confirmation to prospect prospect_confirmation = await email_service.send_sales_inquiry_confirmation( inquiry.email, inquiry.name ) # Send notification to sales team sales_notification = await email_service.send_sales_inquiry_notification( inquiry.name, inquiry.email, inquiry.company, inquiry.employees, inquiry.use_case, inquiry.message ) if prospect_confirmation and sales_notification: return {"message": "Sales inquiry submitted successfully"} else: raise HTTPException(status_code=500, detail="Failed to process sales inquiry") except Exception as e: raise HTTPException(status_code=500, detail=f"Error processing sales inquiry: {str(e)}") @router.get("/support/chat/config") async def get_chat_config(): # Return configuration for chat widget (Intercom, Zendesk, etc.) return { "enabled": True, "provider": "intercom", "app_id": "your_intercom_app_id", # Should come from environment "settings": { "color": "#0066cc", "position": "bottom-right" } }