o
    h                     @   s  d dl mZmZ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 d dlmZ d dlmZ d dlmZ d dlmZ e Zejd	e
d
eejfdedejfddZejd	ed
e eejeefdedejfddZejde
d
eej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dejdef
ddZ ej!de
d
eejeefdedejdefddZ"dS )    )	APIRouterHTTPExceptionDependsRequest)Optional)database)AccountAccountCreateAccountUpdateAccountsAccountQueryParams)User)get_current_userdetails)accounts)datetime/)response_modelaccountdbc              
   C   s^   z	t | |}|W S  ty } ztdt|dd }~w ty. } ztdddd }~ww )N  status_codedetail  Internal server error)account_servicecreate_account_service
ValueErrorr   str	Exception)r   r   created_accountvee r#   8/var/www/html/moveengine/app/v1/routers/saas/accounts.pycreate_account   s   r%   paramsc                 C   sx   z)t j| j| j| j| j| j| j| j| j	| j
| j| j| j| j||d}td| |W S  ty; } ztdddd }~ww )N)skiplimitqaccount_type	is_activesubscription_statusreg_date_fromreg_date_toworkforce_count_rangefleet_count_rangerevenue_range
account_idreferred_account_idr   current_usersirr   r   r   )r   get_accounts_servicer'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   printr   r   )r&   r   r4   resultr"   r#   r#   r$   get_accounts   s0   
r9   z/{account_id}r2   c              
   C   sV   zt | |}|d u rtddd|W S  ty* } ztddt| dd }~ww )N  Account not foundr   r   zError retrieving account: )r   get_account_servicer   r   r   )r2   r   r   r"   r#   r#   r$   get_account6   s   r=   requestr4   c              
   C   sV   zt | |||}|W S  ty } z|d }~w ty* } ztdddd }~ww )Nr   r   r   )r   update_account_servicer   r   )r2   r   r>   r   r4   updated_accounther"   r#   r#   r$   update_accountC   s   rB   c              
   C   s~   z'| ddkr| d| krtdddt| |}|d u r%tddd|W S  ty> } ztd	d
t| dd }~ww )Nroles   r2   i  zPermission deniedr   r:   r;   r   zError deleting account: )getr   r   delete_account_servicer   r   )r2   r   r4   deleted_accountr"   r#   r#   r$   delete_accountS   s   rH   N)#fastapir   r   r   r   typingr   app.dbr   app.v1.models.saas.accountmodelr   r	   r
   r   r   app.v1.models.saas.usersmodelr   app.v1.dependencies.authr   app.v1.services.saasr   r   r   routerpostget_mongo_dbMongoDBr%   rE   r9   r   r=   rB   deleterH   r#   r#   r#   r$   <module>   sp    