
    Ei
                     B   d dl mZmZ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 d dlmZmZ d dlmZ d dlmZ  ee      Z edd	g
      Zej1                  dej2                  d       edd       edd       ee       e eej4                  ej6                              fdedede	defd       Zej?                  dej@                         ed       edd       ee       e eej6                  ej4                              fdedededz  de	def
d       Z!y)    )	APIRouterFile
UploadFileDependsHTTPExceptionstatusForm)Session)get_session)require_roles)UserRole)ProductImageService)setup_loggerz/api/product-imageszProduct Images)prefixtagsz	/generatez?Generate final image for a project using a template unique_name)status_codesummary.zProject master id)descriptionzTemplate unique nameproject_master_idtemplate_unique_namedbcurrent_userc                 |  K   	 t        j                  || ||j                         d{   }|j                  |j                  |j                  |j
                  |j                  |j                  dS 7 I# t        $ r  t        $ r1 t        j                  d       t        t        j                  d      w xY ww)z
    Frontend will POST project_master_id and template_unique_name.
    This endpoint will generate the final image, product-resized image (if applicable),
    create thumbnails and persist a ProductImage row.
    )session
project_idr   current_user_idN)idr   product_template_idfinal_image_pathfinal_image_thumbnail_pathfinal_image_product_pathz-Unexpected error while generating final imagezFailed to generate image)r   detail)r   generate_for_projectr   r   r   r    r!   r"   r   	Exceptionlogger	exceptionr   HTTP_500_INTERNAL_SERVER_ERROR)r   r   r   r   product_images        N/var/www/html/story-book/Story-Book-python-api/app/api/routes/product_image.py generate_final_image_for_projectr+      s      r1FF(!5(OO	
 
  ""!.!@!@#0#D#D - > >*7*R*R(5(N(N
 	

   rHI(M(MVpqqrs.   B<&A6 A4AA6 3B<4A6 6AB99B<z$/regenerate-image/{product_image_id})r   Nz,Hex color to apply to template's color layerproduct_image_idnew_overlay_imagecolorc                 R   K   t        j                  || |||       d {   S 7 w)N)r   r,   new_overlay_filer.   r   )r   regenerate_single_image)r,   r-   r.   r   r   s        r*    regenerate_single_image_endpointr2   4   s4      %<<)*!   s   '%')"fastapir   r   r   r   r   r   r	   sqlmodelr
   app.db.sessionr   app.api.depsr   app.models.userr   r   "app.services.product_image_servicer   app.core.loggingr   __name__r&   routerpostHTTP_201_CREATED
SUPERADMINADMINintstrr+   patchHTTP_200_OKr2        r*   <module>rF      sa   U U U  & & & B )	h		/7G6H	I ''M   "#3FG $S6L M+& t

!KL	rrr 	r 	r
rB *""   %)IT/]^+& tzz4??!KL! : 		
 	rE   