
    H(ie                         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 d d	lmZ d d
lmZ d dlmZ  G d d      Zy)    )HTTPException)descselect)Session)schema)schemas)JWTPayloadSchema)Messages)TblGroup)TblMainData)TblStoreFormat)CustomResponsec                   f    e Zd ZdedefdZdej                  fdZde	de
ej                     fdZy	)
PreSelectedCategoryServicedbtokenc                      || _         || _        y )N)r   r   )selfr   r   s      L/var/www/html/retail-simulation-api/app/api/pre_selected_category/service.py__init__z#PreSelectedCategoryService.__init__   s    
    requestc                 h  K   | j                   j                  t              j                  t        j                  |j                  k(        j                         }|st        dd      S | j                   j                  t        t              j                  t        j                  |j                  k(  t        j                  |j                  k(  z        j                  t        t        j                               j#                  d            }|j%                         }|st        dd      S |j&                  xs d|j(                  xs d|j*                  xs dd}|j,                  }||vrt        dd      S ||   }t.        j0                  j3                  |      }t5        |      |_        t7        d
i |j9                         }	| j                   j;                  |	       | j                   j=                          | j                   j?                  |	       t        d	t@        jB                        S w)N0Group not found)statusmessage   z,Main data not found for the group's categoryr   )LowMediumHighz6Invalid merchandise value (Low, Medium, High required)1 )"r   queryr   filtergroup_idfirstr   executer   r   whereformat_typecategory_assignedcategoryorder_byr   data_idlimitscalar_one_or_noneno_of_cats_lno_of_cats_mno_of_cats_hmerchandiser   StoreFormateResmodel_validatestrr   
model_dumpaddcommitrefreshr
   
PRE_CREATE)
r   r   groupresult	main_datamerchandise_mapmerchandise_textmerchandise_value	new_storenew_store_dbs
             r   postzPreSelectedCategoryService.post   s    h'..x/@/@GDTDT/TU[[]!6GHH;U((E,C,CC((ENN:< Xd;../0U1X
 --/	!6dee )).Q,,1**/a
 #..?2!6noo+,<=++::7C	!"34	%?	(<(<(>?L!%S(2E2EFFs   H0H2r&   returnc           	      &  K   | j                   j                  t              j                  t        j                  |k(        j                         }|st        dd      | j                   j                  t              j                  t        j                  |k(        j                         }|st        dd      | j                   j                  t              j                  t        j                  |j                  k(  t        j                  |j                  k(  z        j                  t        t        j                              j                         }|st        dd      t!        |j"                  xs d      dt!        |j$                  xs d      dt!        |j&                  xs d      d	i}g }|D ]V  }|j)                  t+        j,                  |j.                  |j1                  |j2                        |j2                  
             X |S w)Ni  z	not found)status_codedetailr   zMain data not foundr   r   r    r!   )store_format_typer4   rB   )r   r$   r   r%   r&   allr   r   r'   r   r*   r+   r,   r-   r   r.   r7   r1   r2   r3   appendr   PreValidation1rJ   getr4   )r   r&   store_formatsr=   r?   r@   responsesfs           r   get_pre_select_categoryz2PreSelectedCategoryService.get_pre_select_categoryB   s    GGMM.)VN++x78SU 	 CDDh'..x/@/@H/LMSSUC8IJJ GGMM+&V((E,C,CC**enn<> Xd;../0UW 	 C8MNN 	&&+!,e	&&+!,h	&&+!,f
 BOO%%&(&:&: / 3 3BNN C&(nn   s   HHN)__name__
__module____qualname__r   r	   r   r   StoreFormateCreate11rE   intlistr   rM   rR   r#   r   r   r   r      sI    7 )9 %G!=!= %G^*c *d6CXCX>Y *r   r   N)fastapir   
sqlalchemyr   r   sqlalchemy.ormr   app.api.pre_selected_categoryr   app.api.store_formater   app.dependency.authanticationr	   app.locale.messagesr
   app.models.main.groupr   app.models.main.main_datar   app.models.main.store_formater   app.utils.schemas_utilsr   r   r#   r   r   <module>rd      s2    ! # " 0 ) : ( * 1 8 2^ ^r   