o
    V
h                     @   s  d dl mZmZmZmZmZmZmZ d dlm	Z	m
Z
mZmZ d dlmZ d dlmZmZ d dlmZ ddlmZ ddlmZmZmZmZmZmZmZ e ZG d	d
 d
eZG dd deZG dd deZ G dd deZ!ej"de!deej#eefdedej$fddZ%ej&de
e! dedddeddded d dedddeej#eefde'd e	e' d!e(d"e(dej$f
d#d$Z)ej&d%e!dedd&deej#eefd'e'dej$fd(d)Z*ej+d%e!deej#eefd'e'd*e dej$fd+d,Z,ej-d%e!dedd&deej#eefd'e'dej$fd-d.Z.ej&d/ee'ef dedd0deej#eefde'dej$fd1d2Z/ej"d3e!dedd4d5d6edd4d7d6eej#eefde'd8e'dej$fd9d:Z0dS );    )	APIRouterDependsHTTPExceptionQueryPathBodyRequest)OptionalListDictAny)datetime)	BaseModelField)database   )get_current_userdetails)create_activity_servicelist_activities_serviceget_activity_serviceupdate_activity_servicedelete_activity_serviceget_support_dashboard_serviceupdate_pipeline_status_servicec                   @   s   e Zd ZU edddZeed< edddZeed< edddZe	e ed	< edd
dZ
e	e ed< edddZe	eeef  ed< dS )SupportActivityBase.zFType of activity, e.g. 'comment', 'meeting', 'note', 'pipeline_update'descriptiontypez(Account ID associated with this activity
account_idNz&ID of the user performing the activityuser_idz0Main content (comment text, meeting notes, etc.)contentz\Extra details (for meetings: scheduled_date, for pipeline updates: old and new status, etc.)additional_data)__name__
__module____qualname__r   r   str__annotations__r   r   r	   r    r!   r   r    r'   r'   7/var/www/html/moveengine/app/v1/routers/saas/support.pyr      s   
 r   c                   @   s   e Zd ZdS )SupportActivityCreateN)r"   r#   r$   r'   r'   r'   r(   r)       s    r)   c                   @   sF   e Zd ZU edddZee ed< edddZee	ee
f  ed< dS )SupportActivityUpdateNzUpdated contentr   r    zUpdated extra detailsr!   )r"   r#   r$   r   r    r	   r%   r&   r!   r   r   r'   r'   r'   r(   r*   #   s   
 $r*   c                   @   s*   e Zd ZU edddZeed< eed< dS )SupportActivity._id)aliasactivity_idcreated_dateN)r"   r#   r$   r   r.   r%   r&   r   r'   r'   r'   r(   r+   '   s   
 r+   /)response_modelactivitydbc              
      sd   | j s| jd|did} zt| |I dH }|W S  ty1 } ztddt| dd}~ww )zy
    Create a new support activity record.
    If account_id is not provided, the current user's account_id is used.
    r   )updateN  zFailed to create activity: status_codedetail)r   copygetr   	Exceptionr   r%   )r2   r3   current_usernew_activityer'   r'   r(   create_activity/   s   
r?   .zAccount ID to filter activitiesr   Nz'Filter by activity type, e.g. 'comment')ge
      r   activity_typeskiplimitc              
      sN   zt | ||||I dH }|W S  ty& } ztddt| dd}~ww )zq
    Retrieve a paginated list of support activities for an account.
    You may filter by the 'type' field.
    Nr5   zFailed to list activities: r6   )r   r;   r   r%   )r   rC   rD   rE   r3   r<   
activitiesr>   r'   r'   r(   list_activitiesA   s   rG   z/{activity_id}zSupport activity IDr.   c              
      X   zt | |I dH }|stddd|W S  ty+ } ztddt| dd}~ww )z>
    Retrieve a single support activity record by its ID.
    N  Activity not foundr6   r5   zFailed to retrieve activity: )r   r   r;   r%   )r.   r3   r<   r2   r>   r'   r'   r(   get_activityT      	rK   activity_updatec              
      sZ   zt | ||I dH }|stddd|W S  ty, } ztddt| dd}~ww )z.
    Update an existing support activity.
    NrI   rJ   r6   r5   zFailed to update activity: )r   r   r;   r%   )r.   rM   r3   r<   updatedr>   r'   r'   r(   update_activitye   s   
rO   c              
      rH   )z+
    Delete a support activity record.
    NrI   rJ   r6   r5   zFailed to delete activity: )r   r   r;   r%   )r.   r3   r<   deletedr>   r'   r'   r(   delete_activityw   rL   rQ   z/dashboard/{account_id}z(Account ID for support dashboard metricsc              
      sH   zt | |I dH }|W S  ty# } ztddt| dd}~ww )z
    Return aggregated support metrics for the account:
      - Count of support comments/notes
      - Count of upcoming meetings
      - (Trial info is handled in subscriptions)
    Nr5   zDashboard error: r6   )r   r;   r   r%   )r   r3   r<   	dashboardr>   r'   r'   r(   support_dashboard   s   rS   z	/pipelineTzAccount ID for pipeline update)embedr   z5New sales pipeline status (e.g. 'trial', 'live paid')
new_statusc              
      sJ   zt | ||I dH }|W S  ty$ } ztddt| dd}~ww )z
    Update the sales pipeline status for an account.
    This endpoint updates the account record and logs the change as a support activity.
    Nr5   zPipeline update failed: r6   )r   r;   r   r%   )r   rU   r3   r<   r2   r>   r'   r'   r(   update_pipeline_status   s   rV   )1fastapir   r   r   r   r   r   r   typingr	   r
   r   r   r   pydanticr   r   app.dbr   dependencies.authr   services.saas.supportr   r   r   r   r   r   r   routerr   r)   r*   r+   postget_mongo_dbMongoDBr?   r:   r%   intrG   rK   putrO   deleterQ   rS   rV   r'   r'   r'   r(   <module>   s   $ $
	






