# 10 — AI Copy Engine

## Context
Fogbreak replaces all 6 platforms (FUB, ShowingTime, Sisu, Paperless Pipeline, DocuSign, RealScout) and adds AI marketing none of them offer. This instruction builds the AI copy generation engine that powers listing descriptions, social captions, email campaigns, neighborhood guides, and all written content across the platform.

## What to Build

### 1. Listing Description Generator
Via AI service (instruction 03):
- Input: property data (beds, baths, sqft, features, photos, address)
- Output: MLS-ready description (multiple lengths: 250 char, 500 char, full)
- Style: brand-voice aware (load from tenant brand config)
- Market-aware: language appropriate to the market (luxury vs. starter home vs. rural)
- SEO-optimized: include searchable terms for the market
- Fair Housing compliant: auto-audit before output (never describe neighborhood demographics)

Create `app/api/marketing.php`:
```
POST /api/marketing.php?action=generate_listing_description
POST /api/marketing.php?action=generate_social_captions
POST /api/marketing.php?action=generate_email_campaign
POST /api/marketing.php?action=generate_neighborhood_guide
POST /api/marketing.php?action=generate_market_update
POST /api/marketing.php?action=generate_open_house_invite
POST /api/marketing.php?action=generate_just_sold
POST /api/marketing.php?action=generate_price_reduction
POST /api/marketing.php?action=audit_fair_housing
```

### 2. Social Caption Generator
Per platform (different style/length for each):
- Instagram: engaging, emoji-friendly, 30 relevant hashtags, call-to-action
- Facebook: longer form, community-focused, shareable
- LinkedIn: professional, market-insight angle, thought-leadership
- TikTok: short, punchy, trend-aware, hook in first line

### 3. Email Campaign Copy
AI generates full drip campaign content:
- Subject lines (A/B variants)
- Body copy personalized to recipient (name, property interest, stage)
- Call-to-action appropriate to campaign goal
- Market update emails with current stats
- Re-engagement emails for dormant leads
- Just-sold announcements
- Price reduction notifications
- Open house invitations

### 4. Neighborhood Guides
AI generates market-aware neighborhood content:
- Overview (vibe, lifestyle, who lives there — Fair Housing compliant)
- Dining, shopping, recreation highlights
- Schools summary (data-driven, no subjective quality claims)
- Commute information
- Market statistics (median price, DOM, inventory)
- Updated dynamically as market data changes

### 5. Blog Post Generator
For agent/brokerage websites:
- Market update posts (monthly/quarterly)
- Buyer tips, seller tips
- Neighborhood spotlights
- Investment analysis
- SEO-optimized with target keywords

### 6. Fair Housing Audit on All Output
EVERY piece of generated copy runs through the Fair Housing auditor before delivery:
- Check for protected class references (race, color, religion, national origin, sex, familial status, disability)
- Check for steering language ("family-friendly", "young professionals", "safe neighborhood")
- Check for discriminatory implications
- Flag and rewrite any violations
- Log audit results for compliance records

### 7. Brand Voice System
Each tenant/brand has configurable voice parameters:
```json
{
    "tone": "warm, sophisticated, knowledgeable",
    "vocabulary_level": "elevated but accessible",
    "avoid_words": ["cheap", "steal", "must-see"],
    "preferred_words": ["curated", "thoughtfully designed", "coastal living"],
    "signature_phrases": ["Four Decades. One Standard."],
    "emoji_use": "minimal",
    "formality": "professional but approachable"
}
```
Stored in tenant config, loaded into AI prompts automatically.

### 8. Content Approval Workflow
- AI generates draft → agent reviews → approve/edit/regenerate
- Approved content queued for distribution
- Edit history tracked
- Regenerate with feedback: "Make it shorter" or "Emphasize the ocean view"

### 9. Template Library
Pre-built prompt templates for common content:
- New listing announcement
- Open house invitation
- Price reduction alert
- Just sold celebration
- Market update (monthly)
- Buyer guide email series
- Seller guide email series
- Holiday/seasonal greetings
- Agent bio/introduction
- Testimonial request

## Frontend
- "Generate" button on every listing detail page
- Content type selector (description, social, email, blog)
- Preview pane with platform-specific formatting
- Edit/regenerate controls
- One-click approve and distribute
- Fair Housing audit badge (green = passed, red = flagged)

## Acceptance Criteria
- [ ] Listing descriptions generated in multiple lengths, brand-voice aware
- [ ] Platform-specific social captions (IG, FB, LinkedIn, TikTok)
- [ ] Full email campaign copy with personalization
- [ ] Neighborhood guides (Fair Housing compliant)
- [ ] Blog post generation with SEO optimization
- [ ] Fair Housing audit on 100% of generated content
- [ ] Brand voice system configurable per tenant
- [ ] Content approval workflow with regeneration
- [ ] Template library for common content types
- [ ] All copy is market-aware and tenant-aware
