
    'j                    f   d Z ddlmZ ddlmZmZ ddlmZ  G d de          Z G d de          Z	 G d	 d
e          Z
 G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          ZdS )a<  Shared Pydantic response schemas for all Chanakya agent REST endpoints.

Widget-based response contract
-------------------------------
Every successful ``POST /query`` response returns a list of *widgets* that
the frontend renders in order.

``text``   -- a plain-English explanation of the data.
``chart``  -- a chart matching the frontend ``ChartWidget`` TypeScript interface.
``table``  -- raw tabular data (columns + rows) for a grid view.

Success shape
-------------
{
    "status": "success",
    "data": [
        { "type": "text",  "content": "Here are the top 5 policy types ..." },
        {
            "type": "chart",
            "content": {
                "chartType":  "bar",
                "title":      "Policies by Type",
                "dataset":    [ {"policy_type": "Health", "count": 150} ],
                "labelField": "policy_type",
                "valueField": "count",
                "labels":  ["Health", "Life"],
                "values":  [150, 120],
                "insight": "Health insurance dominates with 150 policies."
            }
        }
    ],
    "error": null
}

Failure shape
-------------
{
    "status": "failure",
    "data": null,
    "error": {
        "message": "<human-readable explanation>",
        "code":    "PIPELINE_ERROR | DB_ERROR | SAFETY_VIOLATION | NO_DATA"
    }
}
    )annotations)AnyLiteral)	BaseModelc                  ,    e Zd ZU dZdZded<   ded<   dS )
TextWidgetz>A plain-English explanation rendered as prose by the frontend.textzLiteral['text']typestrcontentN)__name__
__module____qualname____doc__r
   __annotations__     =/var/www/html/ai-enterprise-brain/backend/chanakya/schemas.pyr   r   8   s0         HH"D""""LLLLLr   r   c                  H    e Zd ZU dZded<   dZded<   dZded<   dZded	<   dS )
SeriesConfigzNA single data series for multi-series charts (stacked_bar, grouped_bar, line).r   nameNlist[float] | Nonevalues
str | Nonefieldcolor)r   r   r   r   r   r   r   r   r   r   r   r   r   A   sT         XXIII!%F%%%%EEr   r   c                      e Zd ZU dZded<   dZded<   dZded<   dZd	ed
<   dZded<   dZ	ded<   dZ
ded<   dZded<   dZded<   dZded<   dS )ChartWidgetContentzLPayload inside a chart widget -- mirrors the frontend ChartWidget interface.r   	chartTypeNr   titlelist[str] | Nonelabelsr   r   zlist[SeriesConfig] | Noneseriesunitlist[dict[str, Any]] | Nonedataset
labelField
valueFieldinsight)r   r   r   r   r   r    r"   r   r#   r$   r&   r'   r(   r)   r   r   r   r   r   I   s         VVNNNE#F####!%F%%%%(,F,,,,D+/G////!J!!!!!J!!!!Gr   r   c                  (    e Zd ZU dZded<   ded<   dS )ChartWidgetchartzLiteral['chart']r
   r   r   Nr   r   r   r
   r   r   r   r   r+   r+   W   /         $D$$$$r   r+   c                  $    e Zd ZU ded<   ded<   dS )TableWidgetContent	list[str]columnslist[dict[str, Any]]rowsN)r   r   r   r   r   r   r   r0   r0   _   s*         r   r0   c                  (    e Zd ZU dZded<   ded<   dS )TableWidgettablezLiteral['table']r
   r0   r   Nr-   r   r   r   r6   r6   d   r.   r   r6   c                  (    e Zd ZU dZded<   ded<   dS )	ErrorInfoz1Error payload returned when an agent query fails.r   messagecodeN)r   r   r   r   r   r   r   r   r9   r9   l   s(         ;;LLLIIIIIr   r9   c                  H    e Zd ZU dZded<   g Zded<   dZded<   dZded<   d	S )
TatasteelAgentOutputz5Structured output from the Tatasteel NL-to-SQL agent.r   explanationr1   what_to_act_on urgencycost_of_inactionN)r   r   r   r   r   r?   rA   rB   r   r   r   r=   r=   u   sX         ?? "N""""Gr   r=   c                  H    e Zd ZU dZded<   dZded<   dZded<   dZd	ed
<   dS )AgentQueryRequestzBInbound body for a ``POST /query`` endpoint on any Chanakya agent.r   questionNr   
user_email
int | Noneconversation_idr%   history)r   r   r   r   r   rF   rH   rI   r   r   r   rD   rD   }   sT         LLMMM!J!!!!"&O&&&&+/G//////r   rD   c                      e Zd ZU dZded<   ded<   ded<   dZded	<   dZd
ed<   g Zded<   dZded<   dZ	ded<   dZ
ded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dS )UIRenderRequestzInbound body for ``POST /render`` on the UI agent.

    Contains the original user question, the plain-text explanation from the
    data agent, and the raw query rows to visualise.
    r   rE   r>   r3   r4   Nr   rF   rG   rH   progress_stepsGBPcurrency_codemarket_contextr!   storyline_hintsr%   decision_support_contextgenerated_sqlsql_explanationdc_explanationzlist[dict[str, str]] | NonerI   r?   rA   rB   )r   r   r   r   r   rF   rH   rL   rN   rO   rP   rQ   rR   rS   rT   rI   r?   rA   rB   r   r   r   rK   rK      s3         
 MMM!J!!!!"&O&&&&+-N----M!%N%%%%(,O,,,,<@@@@@ $M$$$$"&O&&&& "&N%%%% ,0G////'+N++++G#'''''''r   rK   c                  j    e Zd ZU dZded<   dZded<   dZded<   edd            Zedd            Z	dS )AgentQueryResponsezTop-level JSON envelope for all agent query responses.

    ``data`` is a list of widgets ordered for sequential rendering.
    Either ``data`` or ``error`` will be non-null, never both.
    r   statusNr%   datazErrorInfo | Noneerrorwidgetsr3   return'AgentQueryResponse'c                    | d|d          S )z9Convenience constructor for a successful widget response.successNrW   rX   rY   r   )clsrZ   s     r   r^   zAgentQueryResponse.success   s     s)'>>>>r   r:   r;   c               <     | ddt          ||                    S )z/Convenience constructor for a failure response.failureN)r:   r;   r_   )r9   )r`   r:   r;   s      r   rb   zAgentQueryResponse.failure   s3     sG$777
 
 
 	
r   )rZ   r3   r[   r\   )r:   r   r;   r   r[   r\   )
r   r   r   r   r   rX   rY   classmethodr^   rb   r   r   r   rV   rV      s          
 KKK(,D,,,,"E""""? ? ? [? 
 
 
 [
 
 
r   rV   N)r   
__future__r   typingr   r   pydanticr   r   r   r   r+   r0   r6   r9   r=   rD   rK   rV   r   r   r   <module>rg      s'  , ,Z # " " " " "                         9                   )             
         )          	       9   0 0 0 0 0	 0 0 0 (  (  (  (  (i  (  (  (F
 
 
 
 
 
 
 
 
 
r   