
    	h                         d dl Z d dlmZ d dlZd dl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 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)JWTPayloadSchema)Messages)HTTPException)CategoryWishInventoryBaseTblCategoryWishInventory)TblGrossMarginContribution)TblGroup)CustomResponse)Sessionc                       e Zd ZdedefdZdej                  fdZddZ	de
dee   fd	Zde
fd
Zdeej                      fdZde
fdZy)CategoryWishInventoryServicedbtokenc                      || _         || _        y )N)r   r   )selfr   r   s      N/var/www/html/retail-simulation-api/app/api/category_wish_inventory/service.py__init__z%CategoryWishInventoryService.__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_wish_inventoryr   commitr   r   CATEGORY_WISH_INVENTORY)r   r   created_category_wish_inventorys      r   r   z;CategoryWishInventoryService.create_category_wish_inventory   sZ     *C*R*RSZSeSeSg*h' ??@_aeahahiS(2R2RSSs   A9A;returnc                 N  K   | j                   j                  t        j                  t        j                        j                  t        j                  t        j                  k(        j                         }|st        dd      t        j                  j                  |      S wN  zGet group ID not foundstatus_codedetail)r   queryr
   contribution_to_gross_margincontribution_to_total_salesfiltergroup_idr	   firstr   r   MarginSalesr   )r   gets     r   r1   z CategoryWishInventoryService.get   s     ggmm6SSUo  VL  VL  M  T  T  Uo  Ux  Ux  |T  |]  |]  U]  ^  d  d  fC8PQQ!!0055s   B#B%r.   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                  |      }|j                  t        j                  d t        j                   d t        j                    d i      }|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.   r/   r   excel_pre_selectospathexistspd
read_excelreplacenpnaninfdropnatolist)r   r.   get_category_name
excel_filedfs        r   get_category_name_excelz4CategoryWishInventoryService.get_category_name_excel!   s      GGMM(3::8;L;LPX;XY__a CDD&77

!;C8kll]]:&ZZrvvtbffWdCD"#**,3355s   DDc                    K   t        j                  || j                        }|st        dd      |D cg c]!  }t        j
                  j                  |      # c}S c c}w wr%   )r	   get_group_idr   r   r   CategoryWishInventoryResponser   )r   r.   new_get_group_id	get_groups       r   rD   z)CategoryWishInventoryService.get_group_id.   sZ     3@@477SC8PQQ`pq`pS\44CCIN`pqqqs   4A$&AA$c                 <  K   |D ]y  }t        j                  |j                               }|j                  t	        dt
        j                        c S t        j                  |j                  || j                         { t	        dt
        j                        S wNz-1r   r   )r   r   r   category_wish_idr   r   CATEGORY_WISH_INVENTORY_NOTr	   update_category_wish_inventoryr   CATEGORY_WISH_INVENTORY_UPDATE)r   r   requpdated_category_wish_inventorys       r   rL   z;CategoryWishInventoryService.update_category_wish_inventory5   s     C.G.V.VWZWeWeWg.h+.??G%T8;_;_``$CCDcDtDt  wV  X\  X_  X_  `	 
 S(2Y2YZZs   BBrJ   c                    K   t        j                  || j                        }|st        dt        j
                        S t        dt        j                        S wrI   )r	   delete_category_wish_inventoryr   r   r   rK   CATEGORY_WISH_INVENTORY_DELETE)r   rJ   deleted_category_wish_inventorys      r   rQ   z;CategoryWishInventoryService.delete_category_wish_inventory=   sJ     *B*a*abrtxt{t{*|'.!x7[7[\\S(2Y2YZZs   AAN)r#   r	   )__name__
__module____qualname__r   r   r   r   CategoryWishInventoryCreater   r1   intlistdictrB   rD   r   CategoryWishInventoryUpdaterL   rQ    r   r   r   r      s{    ' )9 T6;];] T66S 6DJ 6r# r[4@b@b;c [[C [r   r   )r4   typingr   pandasr7   numpyr:   app.api.category_wish_inventoryr   app.dependency.authanticationr   app.locale.messagesr   fastapir   'app.models.main.category_wish_inventoryr   r	   *app.models.main.gross_margin_contributionsr
   app.models.main.groupr   app.utils.schemas_utilsr   sqlalchemy.ormr   r   r\   r   r   <module>ri      s8    	    2 : ( ! g Q * 2 "2[ 2[r   