o
    "j
                     @   sL   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 G dd deZ
dS )	a]  
ReportController handles various reporting functionalities for the OTT platform.
It provides endpoints to fetch channel access code redemption counts, content ingestion summaries,
user engagement summaries, and more. The controller interacts with multiple databases including MongoDB,
MySQL, and Cassandra to gather and aggregate data efficiently.
    )current_app)
get_loggerperformance_log)BaseController)
MySQLModelc                       s:   e Zd ZdZ fddZedd ZdefddZ  Z	S )	ReportControllerz
    Report controller with PHP trait-like API response functionality.
    Inherits from BaseController to get direct access to response methods like PHP traits.
    c                    s    t    t | _td| _d S )Nreport_controller)super__init__r   mysqlr   logger)self	__class__ ?/var/www/html/oms-prod-mcp/app/controllers/report_controller.pyr
      s   
zReportController.__init__c                 C   s   dS )a3  
        Fetch the count of users who have redeemed channel access codes.
        Note: Caching is handled at the route level for better efficiency.

        Args:
            validated_query: Validated ActiveUsersRequest instance

        Returns:
            API response with user count or error
        Nr   )r   validated_queryr   r   r   $get_channel_access_code_redeem_count   s    z5ReportController.get_channel_access_code_redeem_countreturnc              
   C   s   zD| j d | j dd}g }| D ]\}}|dkr.t|tr.|ddkr.|| q|r?d|d< ||d< | 	|W S | 
|W S  tyn } z| j jd	t| d
d | dt|jdW  Y d}~S d}~ww )z~
        Check health status of all databases.

        Returns:
            API response with database health status
        zChecking database health statushealthy)r   overall_statusr   status	connecteddegradedfailed_databasesz Error checking database health: T)exc_infozFailed to check database health)message
error_typeN)r   infor   test_connectionitems
isinstancedictgetappendservice_unavailableok	Exceptionerrorstrserver_errortype__name__)r   health_statusr   db_namer   er   r   r   get_database_health&   s6   
z$ReportController.get_database_health)
r,   
__module____qualname____doc__r
   r   r   tupler0   __classcell__r   r   r   r   r      s    
r   N)r3   flaskr   app.utils.helpersr   r   app.controllers.base_controllerr   app.models.mysql_modelr   r   r   r   r   r   <module>   s    