from fastapi import APIRouter

from app import __version__
from app.core.config import settings

router = APIRouter()

_PAGE_TYPES = [
    "landing",
    "mini_site",
    "business_website",
    "portfolio",
    "restaurant",
    "cafe",
    "company",
    "business_profile",
    "digital_menu",
    "digital_catalog",
    "product_catalog",
    "qr",
    "link_in_bio",
    "appointment",
    "form",
    "blog",
    "campaign",
    "knowledge",
    "documentation",
    "media",
    "seo",
    "public_profile",
    "event",
    "custom",
]

_COMPONENT_KINDS = [
    "layout_block",
    "content",
    "media",
    "navigation",
    "form_shell",
    "widget_shell",
    "cta",
    "hero",
    "menu_ref",
    "catalog_ref",
    "custom",
]

_DIRECTION_MODES = ["rtl", "ltr", "both"]


@router.get("/health")
async def health_check():
    return {
        "status": "ok",
        "service": settings.service_name,
        "version": __version__,
    }


@router.get("/capabilities")
async def capabilities():
    return {
        "service": settings.service_name,
        "version": __version__,
        "phase": "11.10",
        "commercial_product": "Torbat Pages",
        "platform": "Experience Platform",
        "features": {
            "foundation": True,
            "health": True,
            "capabilities": True,
            "metrics": True,
            "workspaces": True,
            "locale_profiles": True,
            "external_providers_ready": True,
            "future_render_engines_ready": True,
            "feature_toggle_shell": True,
            "bundle_licensing_shell": True,
            "sites": True,
            "pages": True,
            "page_types": True,
            "site_domains": True,
            "publishing_draft_archive": True,
            "components": True,
            "component_versions": True,
            "component_version_immutability": True,
            "page_component_placements": True,
            "themes": True,
            "theme_versions": True,
            "layouts": True,
            "layout_versions": True,
            "directionality_ready_shells": True,
            "site_theme_bindings": True,
            "page_layout_bindings": True,
            "page_builder": False,
            "templates": True,
            "template_versions": True,
            "template_instantiation": True,
            "site_locale_bindings": True,
            "localizations": True,
            "rtl_ltr": True,
            "media_refs": True,
            "storage_media_refs_only": True,
            "forms": True,
            "form_submissions": True,
            "surveys": True,
            "survey_responses": True,
            "appointment_pages": True,
            "appointment_booking_refs": True,
            "publishing": True,
            "publish_releases": True,
            "domain_edge_bindings": True,
            "seo_metadata": True,
            "sitemap_shells": True,
            "robots_shells": True,
            "pwa_manifests": True,
            "bundles": True,
            "bundle_definitions": True,
            "tenant_bundles": True,
            "license_bindings": True,
            "feature_toggles": True,
            "widgets": True,
            "consumer_connectors": True,
            "analytics": True,
            "ai_content": True,
            "cms": False,
            "seo_engine": True,
        },
        "page_types": list(_PAGE_TYPES),
        "component_kinds": list(_COMPONENT_KINDS),
        "direction_modes": list(_DIRECTION_MODES),
        "text_directions": ["rtl", "ltr"],
        "localization_targets": [
            "site",
            "page",
            "component_placement",
            "template",
            "theme",
            "layout",
            "media_ref",
        ],
        "media_kinds": ["image", "video", "document", "audio", "icon", "other"],
        "independence": {
            "standalone": True,
            "superapp": True,
            "integrations": [
                "core",
                "storage",
                "crm",
                "hospitality",
                "marketplace",
                "sports_center",
                "communication",
                "loyalty",
                "accounting",
                "delivery",
                "ai",
                "automation",
            ],
            "integration_mode": "api_and_events_only",
        },
    }


@router.get("/metrics")
async def metrics():
    return {
        "service": settings.service_name,
        "version": __version__,
        "phase": "11.10",
        "metrics": {
            "workspaces": "tenant_scoped",
            "sites": "tenant_scoped",
            "pages": "tenant_scoped",
            "site_domains": "tenant_scoped",
            "components": "tenant_scoped",
            "component_versions": "tenant_scoped",
            "page_component_placements": "tenant_scoped",
            "themes": "tenant_scoped",
            "theme_versions": "tenant_scoped",
            "layouts": "tenant_scoped",
            "layout_versions": "tenant_scoped",
            "site_theme_bindings": "tenant_scoped",
            "page_layout_bindings": "tenant_scoped",
            "templates": "tenant_scoped",
            "template_versions": "tenant_scoped",
            "template_instantiations": "tenant_scoped",
            "site_locale_bindings": "tenant_scoped",
            "localizations": "tenant_scoped",
            "media_refs": "tenant_scoped",
            "forms": "tenant_scoped",
            "form_submissions": "tenant_scoped",
            "surveys": "tenant_scoped",
            "survey_responses": "tenant_scoped",
            "appointment_pages": "tenant_scoped",
            "appointment_booking_refs": "tenant_scoped",
            "publish_releases": "tenant_scoped",
            "domain_edge_bindings": "tenant_scoped",
            "seo_metadata": "tenant_scoped",
            "sitemap_shells": "tenant_scoped",
            "robots_shells": "tenant_scoped",
            "pwa_manifests": "tenant_scoped",
            "bundle_definitions": "tenant_scoped",
            "tenant_bundles": "tenant_scoped",
            "license_bindings": "tenant_scoped",
            "feature_toggles": "tenant_scoped",
            "consumer_connector_registrations": "tenant_scoped",
            "consumer_connector_dispatches": "tenant_scoped",
            "widget_definitions": "tenant_scoped",
            "widget_instances": "tenant_scoped",
            "notify_dispatches": "tenant_scoped",
            "analytics_report_definitions": "tenant_scoped",
            "analytics_snapshots": "tenant_scoped",
            "ai_content_hook_registrations": "tenant_scoped",
            "ai_content_dispatches": "tenant_scoped",
            "published_component_versions": "tenant_scoped",
            "locale_profiles": "tenant_scoped",
            "external_providers": "tenant_scoped",
            "render_engines": "tenant_scoped",
            "configurations": "tenant_scoped",
            "published_pages": "tenant_scoped",
            "active_sites": "tenant_scoped",
        },
        "note": "Operational counters reserved for later phases; foundation exposes discovery only",
    }
