"""Site configuration for North Carolina Senior Benefits & Family Care.

Replace bracketed placeholders after legal, licensing, and compliance review.
Tracking IDs stay empty until pixels and conversion tags are installed.
"""

from __future__ import annotations

import os
from datetime import date
from pathlib import Path


def _load_dotenv() -> None:
    path = Path(__file__).resolve().parent / ".env"
    if not path.exists():
        return
    for line in path.read_text(encoding="utf-8").splitlines():
        line = line.strip()
        if not line or line.startswith("#") or "=" not in line:
            continue
        key, value = line.split("=", 1)
        key = key.strip()
        value = value.strip().strip('"').strip("'")
        os.environ.setdefault(key, value)


_load_dotenv()


def env(name: str, default: str = "") -> str:
    value = os.environ.get(name)
    return value if value not in (None, "") else default


SITE_NAME = "North Carolina Senior Benefits & Family Care"
SITE_ABBR = "NCSBFC"
SITE_EDITION = "NCSBFC Families"
SITE_EDITION_NOTE = "Photo-led family site"
LEGAL_BUSINESS_NAME = env("LEGAL_BUSINESS_NAME", "")
DBA = SITE_NAME
POSITIONING = (
    "North Carolina Senior Benefits & Family Care helps North Carolina residents "
    "understand and explore final-expense life-insurance options that may help with "
    "funeral, burial, cremation, medical balances, and other end-of-life expenses."
)
TAGLINE = POSITIONING
LOGO_TAGLINE = "Clear guidance for North Carolina families"
# Original uploaded artwork — do not substitute generated or cropped marks.
BRAND_ASSETS = {
    "original_pdf": "brand-assets/originals/NCSBFC-Logo-BW.pdf",
    "original_jpg": "brand-assets/originals/NCSBFC-Logo-BW.jpg",
    "original_ai": "brand-assets/originals/NCSBFC-Logo.ai",
    "web_logo": "images/ncsbfc-logo.jpg",
    "web_logo_webp": "images/ncsbfc-logo.webp",
    "og_image": "images/og-default.jpg",
    "icon": "images/ncsbfc-icon.png",
    "favicon": "images/favicon.ico",
}

# Company contact. No public click-to-call number is published.
PHONE_DISPLAY = env("PHONE_DISPLAY", "")
PHONE_E164 = env("PHONE_E164", "")
PHONE_TEL = env("PHONE_TEL", "")
EMAIL_DISPLAY = env("EMAIL_DISPLAY", "info@ncsbfc.com")
EMAIL_HREF = env("EMAIL_HREF", "mailto:info@ncsbfc.com")
ADDRESS_DISPLAY = env("ADDRESS_DISPLAY", "PO Box 2085, Wilmington, NC 28402")
ADDRESS_PO_BOX = env("ADDRESS_PO_BOX", "2085")
ADDRESS_CITY = env("ADDRESS_CITY", "Wilmington")
ADDRESS_REGION = env("ADDRESS_REGION", "NC")
ADDRESS_POSTAL = env("ADDRESS_POSTAL", "28402")
NC_LICENSE_NUMBER = env("NC_LICENSE_NUMBER", "1000004747")
NPN = env("NPN", "7834989")

COMPANY_MISSION = (
    "Our goal is to help North Carolina families understand their choices "
    "without pressure, so they can make an informed decision."
)

INDEPENDENT_STATUS = "Licensed insurance agency in North Carolina"
INDEPENDENT_STATUS_SHORT = "Licensed insurance agency in North Carolina"

COMPLIANCE_APPROVAL_REFERENCE = env("COMPLIANCE_APPROVAL_REFERENCE", "")
LAST_REVIEWED = env("LAST_REVIEWED", "September 17, 2026")

SITE_URL = env("SITE_URL", "http://127.0.0.1:5050").rstrip("/")
SECRET_KEY = env("SECRET_KEY", "change-me-in-production-ncsbfc")
ADMIN_TOKEN = env("ADMIN_TOKEN", "ncsbfc-admin-change-me")

# Lead routing placeholders — set any of these to enable live forwarding.
LEAD_WEBHOOK_URL = env("LEAD_WEBHOOK_URL")
ZAPIER_WEBHOOK_URL = env("ZAPIER_WEBHOOK_URL")
MAKE_WEBHOOK_URL = env("MAKE_WEBHOOK_URL")
GOOGLE_SHEETS_WEBHOOK_URL = env("GOOGLE_SHEETS_WEBHOOK_URL")
CRM_WEBHOOK_URL = env("CRM_WEBHOOK_URL")
LEAD_NOTIFY_EMAIL = env("LEAD_NOTIFY_EMAIL", "info@ncsbfc.com")
SMTP_HOST = env("SMTP_HOST", "localhost")
SMTP_PORT = int(env("SMTP_PORT", "587") or "587")
SMTP_USER = env("SMTP_USER", "")
SMTP_PASSWORD = env("SMTP_PASSWORD", "")
SMTP_FROM = env("SMTP_FROM", "info@ncsbfc.com")
SMTP_USE_TLS = env("SMTP_USE_TLS", "true").lower() in {"1", "true", "yes"}

# Tracking placeholders. Leave blank until tags are approved and installed.
META_PIXEL_ID = env("META_PIXEL_ID")
GOOGLE_ADS_ID = env("GOOGLE_ADS_ID")  # e.g. AW-XXXXXXXXX
GOOGLE_ADS_CONSUMER_CONVERSION = env("GOOGLE_ADS_CONSUMER_CONVERSION")
GOOGLE_ADS_AGENT_CONVERSION = env("GOOGLE_ADS_AGENT_CONVERSION")

LEGAL_DISCLOSURE = (
    "NCSBFC is an independent insurance agency and is not affiliated with or "
    "endorsed by the U.S. government, Medicare, Medicaid, or the Social Security "
    "Administration. Insurance products are subject to policy terms, underwriting, "
    "eligibility, availability, and state requirements. Not all products are "
    "available in all areas."
)
DBA_DISCLOSURE = ""

CONSUMER_CONSENT = (
    "By submitting this form, you agree that North Carolina Senior Benefits & "
    "Family Care and its licensed representatives may contact you by phone, email, "
    "and text message at the contact information provided regarding insurance "
    "products. Consent is not required as a condition of purchase. Message and "
    "data rates may apply."
)

AGENT_CONSENT = (
    "By submitting this form, you agree that NCSBFC may contact you by phone, "
    "email, and text message regarding agent opportunities, training, contracting, "
    "business support, and related insurance-professional resources. Consent is "
    "not required as a condition of obtaining information. Message and data rates "
    "may apply."
)

VARIABILITY_DISCLAIMER = (
    "Eligibility, premiums, coverage, policy features, carrier availability, and "
    "waiting periods vary by age, health history, tobacco use, insurer, policy, "
    "underwriting, and North Carolina or other state requirements."
)

AGE_RANGES = [
    "50–54",
    "55–59",
    "60–64",
    "65–69",
    "70–74",
    "75–79",
    "80–85",
    "Prefer not to say",
]

COVERAGE_AMOUNTS = [
    "$5,000",
    "$10,000",
    "$15,000",
    "$20,000+",
    "Not sure",
]

CONTACT_TIMES = [
    "Morning",
    "Afternoon",
    "Evening",
    "Anytime",
]

TOBACCO_OPTIONS = [
    "Yes",
    "No",
    "Prefer not to say",
]


def public_config() -> dict:
    """Values safe to expose to templates and client-side config."""
    return {
        "site_name": SITE_NAME,
        "site_abbr": SITE_ABBR,
        "site_edition": SITE_EDITION,
        "site_edition_note": SITE_EDITION_NOTE,
        "dba": DBA,
        "tagline": TAGLINE,
        "positioning": POSITIONING,
        "logo_tagline": LOGO_TAGLINE,
        "brand_assets": BRAND_ASSETS,
        "phone_display": PHONE_DISPLAY,
        "phone_e164": PHONE_E164,
        "phone_tel": PHONE_TEL,
        "email_display": EMAIL_DISPLAY,
        "email_href": EMAIL_HREF,
        "address_display": ADDRESS_DISPLAY,
        "address_po_box": ADDRESS_PO_BOX,
        "address_city": ADDRESS_CITY,
        "address_region": ADDRESS_REGION,
        "address_postal": ADDRESS_POSTAL,
        "nc_license_number": NC_LICENSE_NUMBER,
        "npn": NPN,
        "company_mission": COMPANY_MISSION,
        "independent_status": INDEPENDENT_STATUS,
        "independent_status_short": INDEPENDENT_STATUS_SHORT,
        "compliance_approval_reference": COMPLIANCE_APPROVAL_REFERENCE,
        "last_reviewed": LAST_REVIEWED,
        "site_url": SITE_URL,
        "legal_disclosure": LEGAL_DISCLOSURE,
        "consumer_consent": CONSUMER_CONSENT,
        "agent_consent": AGENT_CONSENT,
        "variability_disclaimer": VARIABILITY_DISCLAIMER,
        "meta_pixel_id": META_PIXEL_ID,
        "google_ads_id": GOOGLE_ADS_ID,
        "google_ads_consumer_conversion": GOOGLE_ADS_CONSUMER_CONVERSION,
        "google_ads_agent_conversion": GOOGLE_ADS_AGENT_CONVERSION,
        "today": date.today().isoformat(),
        "age_ranges": AGE_RANGES,
        "coverage_amounts": COVERAGE_AMOUNTS,
        "contact_times": CONTACT_TIMES,
        "tobacco_options": TOBACCO_OPTIONS,
        "lead_integrations": {
            "file_store": "Enabled (local JSON)",
            "webhook": "Configured" if LEAD_WEBHOOK_URL else "Placeholder",
            "zapier": "Configured" if ZAPIER_WEBHOOK_URL else "Placeholder",
            "make": "Configured" if MAKE_WEBHOOK_URL else "Placeholder",
            "google_sheets": "Configured" if GOOGLE_SHEETS_WEBHOOK_URL else "Placeholder",
            "crm": "Configured" if CRM_WEBHOOK_URL else "Placeholder",
            "email_notify": "Configured" if LEAD_NOTIFY_EMAIL else "Placeholder",
        },
    }
