
    Eh                         d dl Z d dlm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)List)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ej                      fdZde	fdZy)!CategoryCaptinshipPlanningServicedbtokenc                      || _         || _        y )N)r   r   )selfr   r   s      S/var/www/html/retail-simulation-api/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   r0   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                 p  K   |D ]y  }t        j                  |j                               }|j                  t	        dt
        j                        c S t        j                  |j                  || 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   r   #CATEGORY_CAPTINSHIP_PLANNING_UPDATE)r   r   req$updated_category_captinship_plannings       r   rG   zECategoryCaptinshipPlanningService.update_category_captinship_planning1   s     C3Q3`3`adaoaoaq3r03DDL%T8;d;dee)MMNr  OD  OD  Fj  lp  ls  ls  t	 
 	S(2^2^__s   B4B6rE   c                    K   t        j                  || j                        }|st        dt        j
                        S t        dt        j                        S wrD   )r   #delete_category_captinship_planningr   r   r   rF   #CATEGORY_CAPTINSHIP_PLANNING_DELETE)r   rE   $deleted_category_captinship_plannings      r   rL   zECategoryCaptinshipPlanningService.delete_category_captinship_planning:   s]     /L/p/p  rB  DH  DK  DK  0L,3!x7`7`aaS(2^2^__s   AAN)__name__
__module____qualname__r	   r
   r   r    CategoryCaptinshipPlanningCreater"   intr)   r4   listdictrB   r    CategoryCaptinshipPlanningUpdaterG   rL    r   r   r   r      s    ' )9 YFDkDk Yn# nQC QKj Q
6C 
64PT: 
6`VElEl@m `` `r   r   )r8   typingr   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   rW   r   r   <module>rb      s2    	   7 v * ! " : ( 20` 0`r   