# app/modules/analytics/services/analytics_features.py """ Analytics feature provider for the billing feature system. Declares analytics-related billable features (dashboard access, report types, export capabilities). All features are binary (on/off) at the merchant level, so no usage tracking queries are needed. """ from __future__ import annotations import logging from typing import TYPE_CHECKING from sqlalchemy import func from app.modules.contracts.features import ( FeatureDeclaration, FeatureProviderProtocol, FeatureScope, FeatureType, FeatureUsage, ) if TYPE_CHECKING: from sqlalchemy.orm import Session logger = logging.getLogger(__name__) class AnalyticsFeatureProvider: """Feature provider for the analytics module. Declares: - analytics_dashboard: binary merchant-level feature for analytics dashboard access - basic_reports: binary merchant-level feature for standard reports - custom_reports: binary merchant-level feature for custom report builder - export_reports: binary merchant-level feature for report data export """ @property def feature_category(self) -> str: return "analytics" def get_feature_declarations(self) -> list[FeatureDeclaration]: return [ FeatureDeclaration( code="analytics_dashboard", name_key="analytics.features.analytics_dashboard.name", description_key="analytics.features.analytics_dashboard.description", category="analytics", feature_type=FeatureType.BINARY, scope=FeatureScope.MERCHANT, ui_icon="bar-chart-2", display_order=10, ), FeatureDeclaration( code="basic_reports", name_key="analytics.features.basic_reports.name", description_key="analytics.features.basic_reports.description", category="analytics", feature_type=FeatureType.BINARY, scope=FeatureScope.MERCHANT, ui_icon="file-text", display_order=20, ), FeatureDeclaration( code="custom_reports", name_key="analytics.features.custom_reports.name", description_key="analytics.features.custom_reports.description", category="analytics", feature_type=FeatureType.BINARY, scope=FeatureScope.MERCHANT, ui_icon="pie-chart", display_order=30, ), FeatureDeclaration( code="export_reports", name_key="analytics.features.export_reports.name", description_key="analytics.features.export_reports.description", category="analytics", feature_type=FeatureType.BINARY, scope=FeatureScope.MERCHANT, ui_icon="download", display_order=40, ), ] def get_store_usage( self, db: Session, store_id: int, ) -> list[FeatureUsage]: # All analytics features are binary; no usage tracking needed return [] def get_merchant_usage( self, db: Session, merchant_id: int, platform_id: int, ) -> list[FeatureUsage]: # All analytics features are binary; no usage tracking needed return [] # Singleton instance for module registration analytics_feature_provider = AnalyticsFeatureProvider() __all__ = [ "AnalyticsFeatureProvider", "analytics_feature_provider", ]