
    rh                        d dl mZmZmZmZ d dlmZ d dlmZm	Z	m
Z
mZ d dlmZmZmZ d dlmZ d dlmZmZ d dlmZmZmZ  edd	g
      Zej3                  de
eef          ee      fdej6                  defd       Zej3                  dej:                         ee      fdej6                  defd       Zej?                  de
eef          edd       edd       ee      fde dede	e   defd       Z!ej?                  de
eef          edd       ee      fde de	e    defd        Z"ej3                  d!e
eef          edd       edd"       edd#       ee      fde de	e    d$e	e    d%e	e    def
d&       Z#y)'    )	APIRouterDependsHTTPExceptionQuery)Session)ListOptionalDictAny)datedatetime	timedelta)get_db)serviceschema)get_twitter_metrics_reportget_latest_performance_score!calculate_store_performance_scorez
/analyticszTwitter Analytics)prefixtagsz/accounts/metrics-report)response_modelrequestdbc                 Z    t        || j                  | j                  | j                        S )a"  
    Generate a comprehensive Twitter metrics report for multiple connected accounts.
    
    This endpoint retrieves stored metrics for the specified accounts and date range,
    and returns a detailed report including aggregated account growth, engagement, and top performing posts.
    )r   account_ids
start_dateend_date)r   r   s     B/var/www/html/hubwallet-dev/src/marketing/apps/Analytics/router.pyget_metrics_reportr   U   s(     &b'*=*=w?Q?QSZScScdd    z/dashboard-analyticsc                 `    ddl m}  ||| j                  | j                  | j                        S )a  
    Get comprehensive social media dashboard analytics for UI display.
    
    This endpoint provides all the metrics needed for the social media analytics dashboard,
    including overall metrics, daily trends, top posts, and engagement data by platform.
    r   )$get_social_media_dashboard_analytics).src.marketing.apps.Analytics.twitter_analyticsr"   r   r   r   )r   r   r"   s      r   get_dashboard_analyticsr$   c   s,     d/G4G4GI[I[]d]m]mnnr    z /accounts/{account_id}/analytics.zStart date for analytics)descriptionNz*End date for analytics (defaults to today)
account_idr   r   c                 $    ddl m}  ||| ||      S )z
    Get analytics for a specific social media account.
    
    This endpoint provides account-specific analytics including top tweets,
    engagement metrics, and performance data for individual accounts.
    r   )get_account_specific_analytics)r#   r(   )r&   r   r   r   r(   s        r   get_account_analyticsr)   r   s     ^)"j*hOOr    z$/stores/{store_id}/performance-scorezOptional branch IDstore_id	branch_idc                     t        || |      S )a6  
    Get performance scores for a store.
    
    This endpoint returns:
    - latest_score: The most recent performance score calculated for the store
    - last_12_months: Array of performance scores for the last 12 months
    
    If no score is present for a month, it returns 0 values for that month.
    )r   )r*   r+   r   s      r   get_store_performance_scorer-      s     (Hi@@r    z./stores/{store_id}/calculate-performance-scorez7Month for calculation (1-12, defaults to current month)z/Year for calculation (defaults to current year)score_month
score_yearc                      t        || |||      S )z
    Calculate and store performance score for a store.
    
    This endpoint calculates the performance score for a specific store and month,
    stores it in the database, and returns the calculated score details.
    )r   )r*   r+   r.   r/   r   s        r   calculate_performance_scorer1      s     -R9kS]^^r    )$fastapir   r   r   r   sqlalchemy.ormr   typingr   r	   r
   r   r   r   r   src.utils.dbr   src.marketing.apps.Analyticsr   r   r#   r   r   r   routerpoststrMetricsReportRequestr   SocialMediaAnalyticsResponser$   getintr)   r-   r1    r    r   <module>r?      sJ   < < " , , . .  8  
,.A-B	CN 'S#XG &/
e((
e
e H
e #F4W4WX &/o((oo Yo .tCH~N S.HI$T7cd&/	PPP tnP 		P OP  24S>R  %T7KL&/AA}A 	A SA" =dSVX[S[n]  %T7KL!&t9r!s %d8i j&/__}_ #_ 	_
 	_ ^_r    