from caracal._version import get_version
"""
Copyright (C) 2026 Garudex Labs.  All Rights Reserved.
Caracal, a product of Garudex Labs

Analytics Extension (Enterprise Stub).

Advanced analytics export and dashboard integration.
In the open-source edition, all methods raise EnterpriseFeatureRequired.
"""

from __future__ import annotations

from typing import Any, Optional

from caracal.sdk.extensions import CaracalExtension
from caracal.sdk.hooks import HookRegistry
from caracal.sdk.enterprise.exceptions import EnterpriseFeatureRequired


class AnalyticsExtension(CaracalExtension):
    """Enterprise analytics export extension.

    Args:
        export_interval: Seconds between automatic metric exports.
    """

    def __init__(self, export_interval: int = 300) -> None:
        self._export_interval = export_interval

    @property
    def name(self) -> str:
        return "analytics"

    @property
    def version(self) -> str:
        return get_version()

    def install(self, hooks: HookRegistry) -> None:
        hooks.on_after_response(self._collect_metrics)

    def _collect_metrics(self, response: Any, scope: Any) -> None:
        raise EnterpriseFeatureRequired(
            feature="Analytics Metrics Collection",
            message="Advanced analytics requires Caracal Enterprise.",
        )

    def export(self, format: str = "json") -> Any:
        """Export analytics data."""
        raise EnterpriseFeatureRequired(
            feature="Analytics Export",
            message="Analytics data export requires Caracal Enterprise.",
        )

    def get_dashboard_url(self) -> str:
        """Get analytics dashboard URL."""
        raise EnterpriseFeatureRequired(
            feature="Analytics Dashboard",
            message="Analytics dashboard requires Caracal Enterprise.",
        )
