
    -6i%                        d Z ddlmZmZmZmZmZ ddlmZm	Z	m
Z
mZmZmZmZmZmZ ddlmZ ddlmZ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#m$Z$m%Z%m&Z&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z-  e       Z.e.j_                  dee0ef          e	e       e	        ede)jb                  d       ede)jb                  d       edd       edd       eddd       ee+jd                  de+jf                  d      fdede&dee0   d ee0   d!e0d"e0d#e4d$e4d%efd&       Z5e.jm                  de#       e	e      fd'e$defd(       Z7e.j_                  d)e#       e	e      fd*e0defd+       Z8e.js                  d)e#       e	e      fd*e0d'e%defd,       Z:e.jw                  d)       e	e      fd*e0defd-       Z<e.jm                  d.       e	e      fd/e'defd0       Z=e.jm                  d1d2ee0ef   3       ed4       ee-j|                  5       e	e       e	e       e	e       ed4d67      fd8ee   d9e-ded:ed;ed*e0d%ee0ef   fd<       Z?e.jw                  d=d>ee0ef   3       e	e       e	e       e	e       ed4d67       ed4d?7      fded:ed;ed*e0d@e4d%ee0ef   fdA       Z@e.jm                  dBdCee0ef   3       ed4dD7       e	e       e	e       e	e      fd'ed*e0ded:ed;ed%ee0ef   fdE       ZAe.js                  dFdCee0ef   3       ed4dD7       ed4dG7       e	e       e	e      fd'ed*e0dHe4ded:ed%ee0ef   fdI       ZBe.j_                  dBdJee0ef   3       ed4dD7       e	e       e	e      fd*e0ded;ed%ee0ef   fdK       ZCe.j_                  dLdMee0ef   3       ed4dN7       e	e       e	e      fd*e0ded;ed%ee0ef   fdO       ZDy)Pz*
Product API router with CRUD operations.
    )ListOptionalDictUnionAny)		APIRouterDependsHTTPExceptionstatusQuery
UploadFileFileFormPath)Session)NoteCreateRequestSchemaNoteUpdateRequestSchema)get_db)get_current_userget_current_merchant)MerchantSchema)
UserSchema)services)ProductResponseSchemaProductCreateSchemaProductUpdateSchemaProductListFilterSchemaProductBulkDeleteSchema)regexp)	constants)	FileTypes/)response_modelNz>Start date of listing to be done. Must be of format YYYY-MM-DD)defaultpatterndescriptionz<End date of listing to be done. Must be of format YYYY-MM-DDz-created_atzZSort column name with direction. Prepend '-' to sort descending. E.g: ?sort_by=-created_at)r$   r&   zAAdditional related fields that are requested. Could be any of ...   z8Number of page that needs to be fetched from the records)r$   ger&   )r$   r(   ler&   dbfilters_from_tosort_byfieldspageper_pagereturnc                 n   K   |dz
  |z  }t        j                  | |||||||d	       d{   }	|	S 7 w)z:
    Retrieve products with filtering and pagination.
    r'   T)	r*   r+   r,   r-   r.   r/   skiplimitpaginateN)r   get_products_list)
r*   r+   r,   r-   r.   r/   r0   r1   r4   results
             V/var/www/html/hwPaymentPortal-be-dev/hw-payment-portal-api/src/apps/products/router.pyr7   r7       sU     N 1H D --
 
F M
s   *535payloadc                 L   K   t        j                  ||        d{   S 7 w)z
    Create a new product.
    )r*   r:   N)r   create_product)r:   r*   s     r9   r<   r<   Y   s+      ((   s   $"$z/{slug}slugc                    K   t        j                  ||        d{   }|st        t        j                  d      |S 7 #w)z 
    Get a product by slug.
    r*   r=   NProduct not foundstatus_codedetail)r   get_productr
   r   HTTP_404_NOT_FOUND)r=   r*   products      r9   rD   rD   j   sM      (( G
 11&
 	
 Ns   AA$Ac                    K   t        j                  || |       d{   }|st        t        j                  d      |S 7 #w)z#
    Update a product by slug.
    )r*   r=   r:   Nr@   rA   )r   update_productr
   r   rE   )r=   r:   r*   updated_products       r9   rH   rH      sQ      %33	 O 11&
 	
 s   AA$Ac                    K   t        j                  ||        d{   }|st        t        j                  d      ddiS 7 %w)z#
    Delete a product by slug.
    r?   Nr@   rA   messagezProduct deleted successfully)r   delete_productr
   r   rE   )r=   r*   successs      r9   rL   rL      sT      ++ G
 11&
 	
 566s   AA&Az/bulk-deletebulk_delete_datac                 r   K   t        j                  || j                         d{   }d| d|dS 7 w)z,
    Delete multiple products by slugs.
    )r*   slugsNzSuccessfully deleted z	 products)rK   deleted_count)r   bulk_delete_productsrP   )rN   r*   rQ   s      r9   rR   rR      sI      #77$$ M +=/C& s   %757z/{slug}/attachmentsz!Upload multiple attachments files)namer#   .)r$   zThe unqiue slug of the product.)r&   files	file_typecurrent_usermerchantc                    K   t        j                  || t        |d      rt        |j                        n
t        |      |||       d {   }|ddS 7 	w)Nvalue)r*   rT   rU   rV   rW   r=   z&Attachment files uploaded successfullydatarK   )r   upload_attachments_fileshasattrstrrY   )rT   rU   r*   rV   rW   r=   responses          r9   create_multiple_filesr`      sZ      66*1)W*E#ioo&3y>! H )QRRs   A	AA
Az/{slug}/attachments/{file_id}zDelete attachments fileszThe unique Id of the file.file_idc                 \   K   t        j                  | ||||       d {   }|ddS 7 	w)N)r*   r=   rW   ra   rV   z&Attachments Files deleted successfullyrZ   )r   delete_attachments_files)r*   rV   rW   r=   ra   r_   s         r9   rc   rc      s?      66! H )QRR   ,*
,z/{slug}/noteszAdd note for ProductzThe slug of the product.c                 \   K   t        j                  || |||       d {   }|ddS 7 	w)N)r*   r:   r=   rW   
created_byzNote created successfullyrZ   )r   create_note)r:   r=   r*   rV   rW   r_   s         r9   rg   rg      s?      )) H )DEErd   z/{slug}/notes/{note_id}zId of the Notenote_idc                 Z   K   t        j                  || ||       d {   }|ddS 7 	w)N)r*   r:   r=   rh   zNote updated successfullyrZ   )r   update_note)r:   r=   rh   r*   rV   r_   s         r9   rj   rj     s9      ))wT7 H )DEEs   +)
+zGet all product notesc                 X   K   t        j                  || |       d {   }|ddS 7 	w)Nr*   r=   rW   zNote fetched successfullyrZ   )r   	list_noter=   r*   rW   r_   s       r9   rm   rm   $  s1      ''2D8LLH)DEE M   *(
*z/{slug}/activitieszGet all customer activitieszThe slug of the productc                 X   K   t        j                  || |       d {   }|ddS 7 	w)Nrl   zActivities fetched successfullyrZ   )r   
activitiesrn   s       r9   rq   rq   5  s1      ((BTHMMH)JKK Nro   )E__doc__typingr   r   r   r   r   fastapir   r	   r
   r   r   r   r   FastAPIFiler   r   sqlalchemy.ormr   $src.apps.notes.schemas.note_requestsr   r   src.core.databaser   src.apps.auth.utils.authr   r   *src.apps.merchants.schemas.merchant_commonr   "src.apps.users.schemas.user_commonr   src.apps.productsr    src.apps.products.schemas.commonr   r   r   r   r   src.apps.base.utilsr   src.core.utilsr    src.core.utils.enumsr!   routergetr^   ISO_DATE_FORMATDEFAULT_PER_PAGEMAX_PER_PAGEintr7   postr<   rD   putrH   deleterL   rR   GALLERYr`   rc   rg   rj   rm   rq        r9   <module>r      si   4 3
 
 
 # a $ K E 9 & ]  ] & $ *	CS#X/&/'.y &&T
 &&R
 p W N
 **!!N	755 %5 C=	5 
#5 5$ %5, -56 75B 	C5 05p S!67 &/  8  I&;< &/
 =, I&;< &/
  	 =0 y &/7
77 7, ^ &/- * 	,S>   *#.	(9(9:&/&'78&';<S&GHS
SS 	S 	S
 S S 
#s(^S
S& #	#S>   &/&'78&';<S&GH)EFSSS S 	S
 S 
#s(^S
S$ 	S>   . &/&'78&';<F$F
F 	F F F 
#s(^F
F( 	S>   . )9:&/&'78F$F
F F 	F F 
#s(^F
F  	 S>   . &/&';<	F
	F
 		F 	F 
#s(^	F
	F 	&S>   - &/&';<	L
	L
 		L 	L 
#s(^	L
	Lr   