
    	,h                         d dl Z d dl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 d dlmZ d dlmZ d d	lmZ  G d
 d      Zy)    N)schema)CategoryCaptinshipPlanningBaseTblCategoryCaptinshipPlanning)TblGroup)HTTPException)Session)JWTPayloadSchema)Messages)CustomResponsec                       e Zd ZdedefdZdej                  fdZde	fdZ
de	d	d
fdZde	d	ee   fdZdej                  fdZde	fdZy)!CategoryCaptinshipPlanningServicedbtokenc                      || _         || _        y )N)r   r   )selfr   r   s      G/var/www/html/RetailAPI/app/api/category_captinship_planning/service.py__init__z*CategoryCaptinshipPlanningService.__init__   s    
    requestc                    K   t        j                  |j                               }t        j                  || j
                         | j
                  j                          t        dt        j                        S w)N1statusmessage)
r   model_validate
model_dumpr   #create_category_captinship_planningr   commitr   r
   CATEGORY_CAPTINSHIP_PLANNING)r   r   $created_category_captinship_plannings      r   'create_category_captinship_planning_newzICategoryCaptinshipPlanningService.create_category_captinship_planning_new   sZ     /M/\/\]d]o]o]q/r,%IIJnptpwpwxS(2W2WXXs   A9A;category_plan_get_idc                    K   t        j                  || j                        }|st        dd      t        j
                  j                  |      S w)N  zGet Category ID not foundstatus_codedetail)r    get_category_captinship_planningr   r   r   "CategoryCaptinshipPlanningResponser   )r   r"   $new_get_category_captinship_plannings      r   r(   zBCategoryCaptinshipPlanningService.get_category_captinship_planning   s]     /L/m/m  oC  EI  EL  EL  0M,3C8STT88GGHlmms   AAgroup_idreturnr   c                 &  K   | j                   j                  t              j                  t        j                  |k(        j                         }|st        dd      |D cg c]!  }t        j                  j                  |      # c}S c c}w w)Nr$   zGet group ID not foundr%   )
r   queryr   filterr+   allr   r   r)   r   )r   r+   *new_get_group_category_captinship_planning	get_groups       r   &get_group_category_captinship_planningzHCategoryCaptinshipPlanningService.get_group_category_captinship_planning   s     59WW]]C`5a5h5h  jG  jP  jP  T\  j\  6]  6a  6a  6c29C8PQQ fP  Q  fPXa99HHS  fP  Q  	Q  Qs   A!B#&B	Bc                   K   | j                   j                  t              j                  t        j                  |k(        j                         }|st        dd      |j                  }|rt        j                  j                  |      st        dd      t        j                  |      }|d   j                         j                         S w)Nr$   z	Not Foundr%   z1Excel file path is invalid or file does not existzCategory Name )r   r.   r   r/   r+   firstr   excel_pre_selectospathexistspd
read_exceldropnatolist)r   r+   get_excel_data
excel_filedfs        r   &get_excel_category_captinship_planningzHCategoryCaptinshipPlanningService.get_excel_category_captinship_planning$   s     x0778I8IX8UV\\^CDD#44

!;C8kll]]:& "#**,3355s   CCc                 *  K   t        j                  |j                               }|j                  t	        dt
        j                        S t        j                  |j                  || j                         t	        dt
        j                        S wNz-1r   r   )r   r   r   category_plan_idr   r
    CATEGORY_CAPTINSHIP_PLANNING_NOTr   #update_category_captinship_planningr   #CATEGORY_CAPTINSHIP_PLANNING_UPDATE)r   r   $updated_category_captinship_plannings      r   rF   zECategoryCaptinshipPlanningService.update_category_captinship_planning0   s     /M/\/\]d]o]o]q/r,/@@H!x7`7`aa%IIJnJJ  Bf  hl  ho  ho  	pS(2^2^__s   BBc                    K   t        j                  || j                        }|st        dt        j
                        S t        dt        j                        S wrC   )r   #delete_category_captinship_planningr   r   r
   rE   #CATEGORY_CAPTINSHIP_PLANNING_DELETE)r   r+   $deleted_category_captinship_plannings      r   rJ   zECategoryCaptinshipPlanningService.delete_category_captinship_planning7   sU     /L/p/pqy{  |C  |C  0D,3!x7`7`aaS(2^2^__s   AAN)__name__
__module____qualname__r   r	   r   r    CategoryCaptinshipPlanningCreater!   intr(   r3   listdictrA    CategoryCaptinshipPlanningUpdaterF   rJ    r   r   r   r      s    ' )9 YFDkDk Yn# nQC QKj Q
6C 
64PT: 
6`@g@g `` `r   r   )r7   pandasr:   $app.api.category_captinship_planningr   ,app.models.main.category_captinship_planningr   r   app.models.main.groupr   fastapir   sqlalchemy.ormr   app.dependency.authanticationr	   app.locale.messagesr
   app.utils.schemas_utilsr   r   rU   r   r   <module>r_      s/    	  7 v * ! " : ( 2.` .`r   