"""
Genesis Gold Pipeline — Industry-Specific Prompt Templates
==========================================================
Modular prompt system for generating landing pages per vertical.
Each template targets a specific industry with tailored copy,
colour schemes, trust signals, and CTAs.

Used by generate_site.py to produce one-shot landing pages via Gemini.
"""

# ---------------------------------------------------------------------------
# Colour palettes per vertical
# ---------------------------------------------------------------------------

PALETTES = {
    "tradie": {
        "primary": "#1e3a5f",       # Deep navy
        "secondary": "#f59e0b",     # Amber/gold
        "accent": "#3b82f6",        # Blue
        "bg": "#f8fafc",
        "desc": "Professional navy and gold — trustworthy trades",
    },
    "plumber": {
        "primary": "#1e40af",       # Royal blue
        "secondary": "#06b6d4",     # Cyan
        "accent": "#f59e0b",
        "bg": "#f0f9ff",
        "desc": "Water-inspired blues — clean and reliable",
    },
    "electrician": {
        "primary": "#7c3aed",       # Electric purple
        "secondary": "#fbbf24",     # Yellow/electric
        "accent": "#4f46e5",
        "bg": "#faf5ff",
        "desc": "Electric purple and yellow — energy and power",
    },
    "hvac": {
        "primary": "#0f766e",       # Teal
        "secondary": "#f97316",     # Orange
        "accent": "#14b8a6",
        "bg": "#f0fdfa",
        "desc": "Cool teal and warm orange — heating and cooling",
    },
    "solar": {
        "primary": "#b45309",       # Amber/brown
        "secondary": "#fbbf24",     # Solar yellow
        "accent": "#65a30d",        # Green
        "bg": "#fffbeb",
        "desc": "Solar gold and earth tones — renewable energy",
    },
    "roofer": {
        "primary": "#78350f",       # Warm brown
        "secondary": "#dc2626",     # Red
        "accent": "#92400e",
        "bg": "#fef2f2",
        "desc": "Earth tones — solid and dependable roofing",
    },
    "dental": {
        "primary": "#0891b2",       # Clean cyan
        "secondary": "#f0fdfa",     # Mint
        "accent": "#06b6d4",
        "bg": "#f0fdfa",
        "desc": "Clinical cyan and mint — clean dental aesthetic",
    },
    "legal": {
        "primary": "#1e293b",       # Charcoal
        "secondary": "#b45309",     # Gold
        "accent": "#334155",
        "bg": "#f8fafc",
        "desc": "Charcoal and gold — authority and prestige",
    },
    "beauty": {
        "primary": "#be185d",       # Rose
        "secondary": "#f9a8d4",     # Pink
        "accent": "#db2777",
        "bg": "#fdf2f8",
        "desc": "Rose and pink — beauty and elegance",
    },
    "realestate": {
        "primary": "#065f46",       # Forest green
        "secondary": "#fbbf24",     # Gold
        "accent": "#047857",
        "bg": "#ecfdf5",
        "desc": "Green and gold — property and growth",
    },
    "mechanic": {
        "primary": "#1f2937",       # Dark grey
        "secondary": "#ef4444",     # Red
        "accent": "#6b7280",
        "bg": "#f9fafb",
        "desc": "Industrial grey and red — automotive reliability",
    },
    "locksmith": {
        "primary": "#374151",       # Steel grey
        "secondary": "#eab308",     # Key gold
        "accent": "#6b7280",
        "bg": "#f9fafb",
        "desc": "Steel and gold — security and trust",
    },
    "generic_ai": {
        "primary": "#7c3aed",       # Violet
        "secondary": "#06b6d4",     # Cyan
        "accent": "#8b5cf6",
        "bg": "#faf5ff",
        "desc": "Tech violet and cyan — AI and innovation",
    },
    "voice": {
        "primary": "#4f46e5",       # Indigo
        "secondary": "#10b981",     # Emerald
        "accent": "#6366f1",
        "bg": "#eef2ff",
        "desc": "Indigo and emerald — voice and intelligence",
    },
    "webdesign": {
        "primary": "#7c3aed",       # Creative purple
        "secondary": "#f43f5e",     # Rose
        "accent": "#a855f7",
        "bg": "#faf5ff",
        "desc": "Creative purple and rose — design and innovation",
    },
}


# ---------------------------------------------------------------------------
# City data for geo-specific pages
# ---------------------------------------------------------------------------

CITIES = {
    "sydney": {
        "state": "NSW",
        "population": "5.3M",
        "suburbs": "Bondi, Parramatta, Chatswood, Penrith, Manly",
        "area_desc": "Greater Sydney and surrounding regions",
    },
    "brisbane": {
        "state": "QLD",
        "population": "2.6M",
        "suburbs": "Southbank, Paddington, Toowong, Carindale, Chermside",
        "area_desc": "Brisbane and South East Queensland",
    },
    "melbourne": {
        "state": "VIC",
        "population": "5.2M",
        "suburbs": "St Kilda, Richmond, Carlton, Footscray, Dandenong",
        "area_desc": "Greater Melbourne and surrounding suburbs",
    },
    "adelaide": {
        "state": "SA",
        "population": "1.4M",
        "suburbs": "Glenelg, Norwood, Unley, Prospect, Semaphore",
        "area_desc": "Adelaide and surrounds",
    },
    "cairns": {
        "state": "QLD",
        "population": "160K",
        "suburbs": "Edge Hill, Whitfield, Smithfield, Palm Cove, Gordonvale",
        "area_desc": "Cairns and Far North Queensland",
    },
    "sunshine_coast": {
        "state": "QLD",
        "population": "350K",
        "suburbs": "Noosa, Maroochydore, Caloundra, Mooloolaba, Nambour",
        "area_desc": "Sunshine Coast region",
    },
    "townsville": {
        "state": "QLD",
        "population": "195K",
        "suburbs": "Castle Hill, Kirwan, Aitkenvale, Belgian Gardens, Cranbrook",
        "area_desc": "Townsville and North Queensland",
    },
    "darwin": {
        "state": "NT",
        "population": "150K",
        "suburbs": "Stuart Park, Fannie Bay, Parap, Nightcliff, Palmerston",
        "area_desc": "Darwin and the Top End",
    },
    "national": {
        "state": "Australia",
        "population": "26M",
        "suburbs": "Sydney, Melbourne, Brisbane, Perth, Adelaide",
        "area_desc": "all of Australia",
    },
}


# ---------------------------------------------------------------------------
# Industry-specific value propositions and features
# ---------------------------------------------------------------------------

VERTICALS = {
    "tradie": {
        "headline": "Never Miss a Job Again",
        "subheadline": "AI-powered voice agents that answer calls, book jobs, and capture leads 24/7",
        "pain_points": [
            "Missing calls while on the tools",
            "Losing jobs to competitors who answer first",
            "Paying $4,000+/month for a human receptionist",
            "No after-hours coverage",
        ],
        "features": [
            "24/7 AI voice receptionist — answers every call",
            "Instant job booking and quote requests",
            "Caller details sent straight to your phone",
            "Works with your existing number",
        ],
        "trust_signals": [
            "Licensed & insured businesses trust us",
            "Australian-built, Australian-hosted",
            "Privacy Act 2026 compliant",
        ],
        "cta": "Hear Your AI Receptionist Now",
        "price_anchor": "From $13/day — less than a coffee run",
    },
    "plumber": {
        "headline": "Your Plumbing Business, Always Open",
        "subheadline": "AI voice agents built for plumbers — capture emergency calls 24/7",
        "pain_points": [
            "Emergency calls at 2am going to voicemail",
            "Losing burst pipe jobs to the plumber who answers",
            "Can't answer while under a house",
            "Weekend calls falling through the cracks",
        ],
        "features": [
            "24/7 emergency call handling",
            "Captures job type, address, and urgency",
            "Prioritises emergencies automatically",
            "SMS notification with caller details",
        ],
        "trust_signals": [
            "Built for licensed plumbers",
            "Understands plumbing terminology",
            "QBCC compliant businesses use us",
        ],
        "cta": "Try Your AI Plumbing Receptionist",
        "price_anchor": "From $13/day — cheaper than one missed emergency call",
    },
    "electrician": {
        "headline": "Power Up Your Business",
        "subheadline": "AI voice agents that handle calls while you're on the job",
        "pain_points": [
            "Can't answer calls while working with live wires",
            "Safety first means missed business second",
            "After-hours emergency calls going unanswered",
            "Competitors answering faster",
        ],
        "features": [
            "Handles calls when your hands are busy",
            "Emergency vs routine call triage",
            "Licence and safety compliance info ready",
            "Books jobs directly into your calendar",
        ],
        "trust_signals": [
            "Built for licensed electricians",
            "Understands electrical terminology",
            "Safety-first approach to call handling",
        ],
        "cta": "Try Your AI Electrical Receptionist",
        "price_anchor": "From $13/day — one answered call pays for a month",
    },
    "dental": {
        "headline": "Your Practice, Always Available",
        "subheadline": "AI voice agents that book appointments, answer patient queries, and never take a sick day",
        "pain_points": [
            "Front desk overwhelmed with calls during peak hours",
            "Patients calling after hours get voicemail",
            "No-shows costing thousands per month",
            "Staff turnover disrupting patient experience",
        ],
        "features": [
            "24/7 appointment booking and confirmation",
            "Automated appointment reminders (reduce no-shows by 30%)",
            "Patient query handling (hours, services, insurance)",
            "Emergency dental triage protocols",
        ],
        "trust_signals": [
            "HIPAA-grade data handling",
            "Australian Privacy Act compliant",
            "Used by dental practices across Australia",
        ],
        "cta": "Try Your AI Dental Receptionist",
        "price_anchor": "From $16/day — less than one no-show costs you",
    },
    "legal": {
        "headline": "Every Call Answered. Every Lead Captured.",
        "subheadline": "AI voice agents built for law firms — professional, discreet, always available",
        "pain_points": [
            "Missing potential client calls during court",
            "After-hours inquiries going to competitors",
            "Receptionist costs eating into margins",
            "Inconsistent call handling across staff",
        ],
        "features": [
            "Professional legal intake handling",
            "Conflict check preliminary screening",
            "Matter type classification and routing",
            "Confidential message handling",
        ],
        "trust_signals": [
            "Law Society compliant practices use us",
            "Confidentiality-first architecture",
            "Australian Privacy Act 2026 ADM compliant",
        ],
        "cta": "Try Your AI Legal Receptionist",
        "price_anchor": "From $16/day — one new client covers a year",
    },
    "beauty": {
        "headline": "Beautiful Bookings, Effortlessly",
        "subheadline": "AI voice agents that book appointments and handle enquiries while you focus on clients",
        "pain_points": [
            "Phone ringing during treatments",
            "Double bookings from manual scheduling",
            "After-hours appointment requests lost",
            "Staff spending hours on phone admin",
        ],
        "features": [
            "Automated appointment booking and confirmation",
            "Service menu and pricing information",
            "Product availability queries",
            "Cancellation and rescheduling management",
        ],
        "trust_signals": [
            "Used by salons across Australia",
            "Integrates with booking systems",
            "Professional and on-brand voice",
        ],
        "cta": "Try Your AI Beauty Receptionist",
        "price_anchor": "From $13/day — book more clients, not phone time",
    },
    "realestate": {
        "headline": "Never Miss a Listing Enquiry",
        "subheadline": "AI voice agents that qualify leads, book inspections, and work 24/7",
        "pain_points": [
            "Weekend inspection calls going to voicemail",
            "Unqualified leads wasting agent time",
            "After-hours buyer enquiries lost to competitors",
            "Tenant maintenance calls overwhelming admin",
        ],
        "features": [
            "24/7 listing enquiry handling",
            "Buyer qualification and pre-screening",
            "Inspection booking and confirmation",
            "Tenant maintenance request logging",
        ],
        "trust_signals": [
            "Used by real estate agencies nationally",
            "Integrates with property CRMs",
            "Professional, brand-consistent voice",
        ],
        "cta": "Try Your AI Property Receptionist",
        "price_anchor": "From $16/day — one commission covers years of service",
    },
    "voice": {
        "headline": "AI Voice Agents for Australian Business",
        "subheadline": "Your business phone, answered by intelligence — 24/7, no missed calls, no voicemail",
        "pain_points": [
            "53% of callers hang up after 3 rings",
            "After-hours calls going to competitors",
            "Human receptionists cost $4,000-6,000/month",
            "Voicemail conversion rate: near zero",
        ],
        "features": [
            "Answers in under 2 seconds, every time",
            "Natural Australian voice — not robotic",
            "Captures caller details and sends to your phone",
            "Works with any business, any industry",
        ],
        "trust_signals": [
            "Australian-built and hosted",
            "Privacy Act 2026 compliant",
            "Patent-protected audit trail technology",
        ],
        "cta": "Hear Your AI Voice Agent Now",
        "price_anchor": "From $13/day — fraction of a receptionist's salary",
    },
    "webdesign": {
        "headline": "AI-Powered Websites That Convert",
        "subheadline": "Professional websites with built-in AI voice agents — designed, built, and deployed in 24 hours",
        "pain_points": [
            "Current website is outdated and not mobile-friendly",
            "Paying $5,000+ for a website redesign",
            "No leads coming from your website",
            "Website builders are confusing and time-consuming",
        ],
        "features": [
            "AI-generated cinematic landing pages",
            "Built-in voice agent that talks to visitors",
            "Mobile-first, lightning-fast performance",
            "SEO-optimised from day one",
        ],
        "trust_signals": [
            "Powered by Google Gemini AI",
            "Australian-designed for local businesses",
            "Live in 24 hours, not 6 weeks",
        ],
        "cta": "See Your New Website in 60 Seconds",
        "price_anchor": "From $397/month — website + AI receptionist included",
    },
    "generic_ai": {
        "headline": "AI That Works for Your Business",
        "subheadline": "Intelligent voice agents, persistent memory, and automation — built for Australian businesses",
        "pain_points": [
            "AI hype but no practical business applications",
            "Complex setup requiring technical expertise",
            "Privacy concerns with overseas AI providers",
            "No Australian-compliant AI solutions",
        ],
        "features": [
            "AI voice agents that answer your phone 24/7",
            "Persistent memory — your AI learns your business",
            "Automated lead capture and CRM integration",
            "Australian-hosted, Privacy Act compliant",
        ],
        "trust_signals": [
            "Australian-built sovereign AI",
            "Patent-protected technology",
            "Privacy Act 2026 ADM reform compliant",
        ],
        "cta": "Try AI for Your Business Now",
        "price_anchor": "From $13/day — enterprise AI at small business prices",
    },
}


# ---------------------------------------------------------------------------
# Domain → vertical/city mapping
# ---------------------------------------------------------------------------

DOMAIN_MAP = {
    # Tier 1: Flagship
    "sunaiva.ai": {"vertical": "generic_ai", "city": None, "tier": 1},
    "sunaiva.com": {"vertical": "generic_ai", "city": None, "tier": 1},
    "sunaiva.com.au": {"vertical": "generic_ai", "city": None, "tier": 1},
    "sunaivadigital.com": {"vertical": "voice", "city": None, "tier": 1},
    "sunaivaradar.com": {"vertical": "generic_ai", "city": None, "tier": 1},
    # Tier 4: City-specific
    "sydneychatbots.com.au": {"vertical": "generic_ai", "city": "sydney", "tier": 4},
    "brisbanechatbots.com.au": {"vertical": "generic_ai", "city": "brisbane", "tier": 4},
    "melbournechatbots.com.au": {"vertical": "generic_ai", "city": "melbourne", "tier": 4},
    "adelaidechatbots.com.au": {"vertical": "generic_ai", "city": "adelaide", "tier": 4},
    "cairnschatbots.com.au": {"vertical": "generic_ai", "city": "cairns", "tier": 4},
    "sunshinecoastchatbots.com.au": {"vertical": "generic_ai", "city": "sunshine_coast", "tier": 4},
    "townsvillechatbots.com.au": {"vertical": "generic_ai", "city": "townsville", "tier": 4},
    "darwinchatbots.com.au": {"vertical": "generic_ai", "city": "darwin", "tier": 4},
    "aichatbotsbrisbane.au": {"vertical": "generic_ai", "city": "brisbane", "tier": 4},
    "aichatbotsaustralia.au": {"vertical": "generic_ai", "city": "national", "tier": 4},
    # Tier 5: Trade-specific
    "tradiechatbots.com.au": {"vertical": "tradie", "city": None, "tier": 5},
    "tradiechatbot.com.au": {"vertical": "tradie", "city": None, "tier": 5},
    "tradiesvoice.com.au": {"vertical": "tradie", "city": None, "tier": 5},
    "tradieautomation.com.au": {"vertical": "tradie", "city": None, "tier": 5},
    "aitradie.au": {"vertical": "tradie", "city": None, "tier": 5},
    "sparkybots.com.au": {"vertical": "electrician", "city": None, "tier": 5},
    "plumberbots.com.au": {"vertical": "plumber", "city": None, "tier": 5},
    "hvacbots.com.au": {"vertical": "hvac", "city": None, "tier": 5},
    "electricianbotai.au": {"vertical": "electrician", "city": None, "tier": 5},
    "solarbotai.au": {"vertical": "solar", "city": None, "tier": 5},
    "mechanicbot.au": {"vertical": "mechanic", "city": None, "tier": 5},
    "locksmithbot.au": {"vertical": "locksmith", "city": None, "tier": 5},
    "rooferbot.au": {"vertical": "roofer", "city": None, "tier": 5},
    # Tier 6: Industry-specific
    "receptionistai.au": {"vertical": "voice", "city": None, "tier": 6},
    "beautybot.com.au": {"vertical": "beauty", "city": None, "tier": 6},
    "propertybotai.com.au": {"vertical": "realestate", "city": None, "tier": 6},
    "propertybotai.au": {"vertical": "realestate", "city": None, "tier": 6},
    "dentalbotai.au": {"vertical": "dental", "city": None, "tier": 6},
    "clinicaibot.au": {"vertical": "dental", "city": None, "tier": 6},
    "lawyerbot.au": {"vertical": "legal", "city": None, "tier": 6},
    "legalbotai.au": {"vertical": "legal", "city": None, "tier": 6},
    "rentbot.au": {"vertical": "realestate", "city": None, "tier": 6},
    # Tier 7: Voice/Receptionist
    "voiceassistant.com.au": {"vertical": "voice", "city": None, "tier": 7},
    "voiceassistant.au": {"vertical": "voice", "city": None, "tier": 7},
    "aivoicereceptionist.au": {"vertical": "voice", "city": None, "tier": 7},
    "phonebot.au": {"vertical": "voice", "city": None, "tier": 7},
    "talkbot.au": {"vertical": "voice", "city": None, "tier": 7},
    "bookingbot.au": {"vertical": "voice", "city": None, "tier": 7},
    # Tier 8: Web Design
    "aiwebdesignsydney.site": {"vertical": "webdesign", "city": "sydney", "tier": 8},
    "aiwebdesignsydney.com.au": {"vertical": "webdesign", "city": "sydney", "tier": 8},
    "aiwebdesignsydney.au": {"vertical": "webdesign", "city": "sydney", "tier": 8},
    "aiwebsitessydney.com.au": {"vertical": "webdesign", "city": "sydney", "tier": 8},
    "aiwebsitessydney.au": {"vertical": "webdesign", "city": "sydney", "tier": 8},
    "aiwebsitesbrisbane.com.au": {"vertical": "webdesign", "city": "brisbane", "tier": 8},
    "ecommercewebsites.site": {"vertical": "webdesign", "city": None, "tier": 8},
    "ecommercewebsites.au": {"vertical": "webdesign", "city": None, "tier": 8},
}


def get_domain_config(domain: str) -> dict:
    """Get the vertical, city, and tier config for a domain."""
    config = DOMAIN_MAP.get(domain, {"vertical": "generic_ai", "city": None, "tier": 9})
    vertical = VERTICALS.get(config["vertical"], VERTICALS["generic_ai"])
    palette = PALETTES.get(config["vertical"], PALETTES["generic_ai"])
    city = CITIES.get(config.get("city") or "", None)
    return {
        "domain": domain,
        "vertical_key": config["vertical"],
        "vertical": vertical,
        "palette": palette,
        "city": city,
        "city_key": config.get("city"),
        "tier": config["tier"],
    }


def get_priority_domains(max_tier: int = 7) -> list:
    """Get domains sorted by tier (lowest tier = highest priority)."""
    domains = [
        (domain, config["tier"])
        for domain, config in DOMAIN_MAP.items()
        if config["tier"] <= max_tier
    ]
    domains.sort(key=lambda x: x[1])
    return [d[0] for d in domains]
