o
    g                     @   s  d Z ddl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 ddlmZ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 ddlmZ e ZedZ eddgdddiig dZ!e Z"e!j#deddedefddZ$e!j%dee ddd Z&e!j%dee dde'fddZ(e!j%d edd!e)fd"d#Z*e!j+d e
j,d$d!e)defd%d&Z-e!j%d'ee dd(d) Z.e!j#d*eddedefd+d,Z/e!j%d-ed.B dde'd!e)fd/d0Z0e!1d1d!e)dedefd2d3Z2d.S )4zFinancial Information router    )	APIRouterHTTPExceptionRequest)JSONResponse)SQLAlchemyError)
HTTPStatus)List) FinancialInformationPageResponseFinancialInformationPageCreate$FinancialInformationTemplateResponse!FinancialInformationTableResponseFinancialInformationTableCreateFinancialInformationPageUpdate)FinancialInformationPageService)#FinancialInformationTemplateService) FinancialInformationTableService)ServiceLogger)MySQLDBWARNINGz/financial_infofinancial_infoi  descriptionz	Not found)prefixtags	responsesdependenciesz/pages)response_model	page_datarequestc              
      f   z|j j}tjtfd|i|  I dH }|W S  ty2 } ztd| t	t
jdd|d}~ww )z2
    Create a new financial information page.
    current_userNzError creating page: %sInternal Server Errorstatus_codedetail)stater   r   insert_new_recordmysql_db
model_dumpr   loggererrorr   r   INTERNAL_SERVER_ERROR)r   r   r   created_pagee r-   6/var/www/html/XCapMarket/controllers/financial_info.pycreate_page$   s(   r/   c               
      N   zt tI dH } | W S  ty& } ztd| ttjdd|d}~ww )z.
    Get all financial information pages.
    NError getting pages: %sr    r!   )	r   get_all_recordsr&   r   r(   r)   r   r   r*   responser,   r-   r-   r.   	get_pages:   s   r5   z/pages/{project_id}
project_idc              
      sP   zt t| I dH }|W S  ty' } ztd| ttjdd|d}~ww )z<
    Get all financial information pages for a project.
    Nr1   r    r!   )	r   get_all_records_for_projectr&   r   r(   r)   r   r   r*   )r6   r4   r,   r-   r-   r.   get_pages_for_projectI   s   
r8   z/page/{page_id}page_idc              
      s^   zt t| I dH }|r|d W S W dS  ty. } ztd| ttjdd|d}~ww )z1
    Get a financial information page by id.
    Nr   zError getting page: %sr    r!   )	r   get_record_by_idr&   r   r(   r)   r   r   r*   )r9   pager,   r-   r-   r.   get_page\   s   
r<   )r"   c              
      sl   z|j j}tjt| d|dI dH  ttjddidW S  ty5 } zt	
d| ttjdd	|d}~ww )
z>
    Mark a financial information page as inactive by id.
    F)	is_activer   Nmessagez$Page marked as inactive successfully)r"   contentz"Error marking page as inactive: %sr    r!   )r$   r   r   update_record_by_idr&   r   r   OKr   r(   r)   r   r*   )r9   r   r   r,   r-   r-   r.   delete_pagem   s&   rB   z
/templatesc               
      r0   )z2
    Get all financial information templates.
    Nr1   r    r!   )	r   r2   r&   r   r(   r)   r   r   r*   r3   r-   r-   r.   get_templates   s   rC   z/save/{project_id}/{page_id}c              
      r   )z2
    Save a financial information page by id.
    r   NzError saving page: %sr    r!   )r$   r   r   save_recordr&   r'   r   r(   r)   r   r   r*   )r   r   r   
saved_pager,   r-   r-   r.   	save_page   s(   rF   z/table/{project_id}/{page_id}Nc              
      sR   zt t|| I dH }|W S  ty( } ztd| ttjdd|d}~ww )z2
    Get a financial information table by id.
    NzError getting table: %sr    r!   )	r   r:   r&   r   r(   r)   r   r   r*   )r6   r9   r4   r,   r-   r-   r.   	get_table   s   
rG   z/pages/{page_id}c              
      sh   z|j j}tjt| fd|i| I dH }|W S  ty3 } ztd| t	t
jdd|d}~ww )z4
    Update a financial information page by id.
    r   NzError updating page: %sr    r!   )r$   r   r   r@   r&   r'   r   r(   r)   r   r   r*   )r9   r   r   r   updated_pager,   r-   r-   r.   update_page   s(   rI   )3__doc__fastapir   r   r   fastapi.responsesr   sqlalchemy.excr   httpr   typingr   schemas.financial_informationr	   r
   r   r   r   r   $services.financial_info.page_servicer   !services.financial_info.templatesr   %services.financial_info.table_servicer   utils.loggerr   utils.mysql_dbr   service_logger
get_loggerr(   r   r&   postr/   getr5   strr8   intr<   delete
NO_CONTENTrB   rC   rF   rG   putrI   r-   r-   r-   r.   <module>   st     



