
    ;h              
       ,   d dl mZmZmZmZmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZmZ  e       Zej#                  dej$                         ee      fdej&                  d	e
fd
       Zej+                  dej,                         edd       edd       ee      fdedee   d	e
fd       Zej+                  deej,                            edd       ee      fded	e
fd       Zej5                  dej,                         edd       edd      d ee      fdedee   dej6                  d	e
fd       Zej;                  d       edd       edd       ee      fdedee   d	e
fd       Zej+                  d      d        Zy)    )	APIRouterDependsHTTPExceptionQueryPath)ListOptional)Session)get_db)
controllerschemaz	/generate)response_modelrequestdbc                 ,   	 t        j                  |      }|j                  | j                  | j                        }|j
                  st        d|j                        |S # t        $ r  t        $ r}t        ddt        |             d}~ww xY w)z
    Generate persona for a store based on post data using Azure LLM.
    
    Analyzes social media posts to identify:
    - Industry
    - Audience type
    - Brand voice
    - Content style
    )store_id	branch_idi  status_codedetail  zError generating persona: N)
r   PersonaControllergenerate_personar   r   successr   message	Exceptionstr)r   r   persona_controllerresultes        @/var/www/html/hubwallet-dev/src/marketing/apps/persona/router.pyr   r      s    ['99"=#44%%'' 5 

 ~~CGG  [6PQTUVQWPX4YZZ[s   A A# #B5BBz/store/{store_id}.zID of the store)descriptionNzOptional branch IDr   r   c                     	 t        j                  |      }|j                  | |      }|st        dd      |S # t        $ r  t        $ r}t        ddt        |             d}~ww xY w)z
    Get existing persona for a store.
    
    Returns the current brand persona analysis including:
    industry, audience type, brand voice, and content style.
       Persona not found for this storer   r   zError retrieving persona: N)r   r   get_personar   r   r   )r   r   r   r   personar    s         r!   get_store_personar(   +   s{    ['99"=$009EC8Z[[  [6PQTUVQWPX4YZZ[s   7: A*A%%A*z/store/{store_id}/listc                     	 t        j                  |      }|j                  |       S # t        $ r}t	        ddt        |             d}~ww xY w)z
    List all personas for a store (including branch-specific ones).
    
    Returns a list of all personas associated with the store,
    including main store persona and any branch-specific personas.
    r   zError listing personas: r   N)r   r   list_store_personasr   r   r   )r   r   r   r    s       r!   r*   r*   F   sV    Y'99"=!55h?? Y6NsSTvh4WXXYs   %( 	AA

Aupdate_datac                     	 t        j                  |      }|j                  | ||      }|st        dd      |S # t        $ r  t        $ r}t        ddt        |             d}~ww xY w)z
    Update existing persona for a store.
    
    Allows manual updates to industry, audience type, brand voice,
    and content style. Only provided fields will be updated.
    r$   r%   r   r   zError updating persona: N)r   r   update_personar   r   r   )r   r   r+   r   r   r'   r    s          r!   r-   r-   Y   sz    Y'99"=$33HiUC8Z[[  Y6NsSTvh4WXXYs   8; A+A&&A+c                     	 t        j                  |      }|j                  | |      }|st        dd      dddS # t        $ r  t        $ r}t        ddt        |             d	}~ww xY w)
zb
    Delete persona for a store.
    
    Soft deletes the persona (sets is_active to false).
    r$   r%   r   TzPersona deleted successfully)r   r   r   zError deleting persona: N)r   r   delete_personar   r   r   )r   r   r   r   r   r    s         r!   r/   r/   u   s    Y'99"=$33HiHC8Z[[,JKK  Y6NsSTvh4WXXYs   := A-A((A-z/healthc                      dddddS )zg
    Health check endpoint for persona service.
    
    Returns basic service status information.
    healthyzLLM Persona Analysisz2.0.0z0Azure LLM-powered store brand persona generation)statusserviceversionr"    r5       r!   persona_health_checkr7      s     )I	 r6   ) fastapir   r   r   r   r   typingr   r	   sqlalchemy.ormr
   src.utils.dbr   src.marketing.apps.personar   r   routerpostPersonaGenerationResponsePersonaGenerationRequestr   getStorePersonaResponseintr(   r*   putPersonaUpdateRequestr-   deleter/   r7   r5   r6   r!   <module>rG      s   B B ! "  9	 [)I)IJ &/[,,[[ K[> 0K0KL*;<$T7KL&/[[}[ 	[ M[4 $T&:U:U5VW*;<&/YYY XY$ 0K0KL*;<$T7KL/3&/	YY}Y ,,Y 		Y MY6 "#*;<$T7KL&/YY}Y 	Y $Y2 I r6   