
    KCj	              	           d Z ddlmZ ddlmZmZmZmZ i ddddddd	dd
ddddddddddddddddddddddddddddddd d d!Z G d" d#e      Z	 G d$ d%e      Z
 G d& d'e      Zy())u  
Input schema for the /analyze endpoint.

This is the single most important validation surface in the system —
every downstream model depends on this data being clean. We validate
aggressively here so bad input never reaches a model and produces a
silently wrong prediction.

Design choice: crop/district lookups are loaded from data/lookup/*.json
at startup (see app/services/reference_data.py) rather than hardcoded
here, so the client coordinator can update supported crops/districts
without a code change and redeploy.
    )Union)	BaseModelFieldfield_validatormodel_validatorjanuary   janfebruary   febmarch   marapril   aprmay   june   junjuly   julaugust   aug	september	   sep
         )septoctoberoctnovembernovdecemberdecc                   2   e Zd ZU  eddddg      Zeed<    eddddg      Zeed	<    edd
dg      Ze	ee
f   ed<    edd      Zedz  ed<    edd	      ededefd              Z ed      ede	ee
f   de
fd              Z ed      dd       Zy)CropAnalysisRequest.r   2   rice)
min_length
max_lengthexamplescropd   	ThanjavurlocationJuner   )r2   monthNzvOptional ID of a saved CropPlan this analysis belongs to (SaaS dashboard use). Omit for one-off / API-key-based calls.)descriptioncrop_plan_idvreturnc                 \    |j                         j                         }|st        d      |S )Nz(Field cannot be empty or whitespace only)striplower
ValueError)clsr;   cleaneds      @C:\Crop_Prediction\Backend\crop-ai-system\app\schemas\request.pystrip_and_lowercasez'CropAnalysisRequest.strip_and_lowercase-   s*     '')//#GHH    c                    t        |t              r$d|cxk  rdk  st        d       t        d      |S t        |t              r}|j	                         j                         }|j                         r/t        |      }d|cxk  rdk  st        d       t        d      |S |t        vrt        d| d      t        |   S t        d      )Nr	   r$   zMonth must be between 1 and 12'z[' is not a recognized month name. Use a full or short English month name, or a number 1-12.z!Month must be a string or integer)
isinstanceintr@   strr>   r?   isdigitMONTH_NAME_TO_NUMBER)rA   r;   keynums       rC   normalize_monthz#CropAnalysisRequest.normalize_month5   s     a<R< !ABB   !ABBHa'')//#C{{}#hC~2~$%EFF &$%EFF
.. s P Q  (,,<==rE   after)modec                     | S )N )selfs    rC   validate_combinationz(CropAnalysisRequest.validate_combinationK   s	     rE   )r<   r-   )__name__
__module____qualname__r   r3   rJ   __annotations__r6   r8   r   rI   r:   r   classmethodrD   rO   r   rU   rS   rE   rC   r-   r-   #   s    caB&JD#J#!{mTHcT"3&!=E5c?=$T L#*  VZ(C C   ) W>c3h >C >  >( '" #rE   r-   c                   4    e Zd ZU dZeed<   dZeed<   eed<   y)TaskSubmissionResponseuJ   Returned immediately by POST /analyze — the job is queued, not done yet.task_idqueuedstatuspoll_urlN)rV   rW   rX   __doc__rJ   rY   r_   rS   rE   rC   r\   r\   T   s    TLFCMrE   r\   c                   J    e Zd ZU eed<   eed<   dZedz  ed<   dZedz  ed<   y)TaskStatusResponser]   r_   Nresulterror)rV   rW   rX   rJ   rY   rd   dictre   rS   rE   rC   rc   rc   [   s(    LKFD4KE3:rE   rc   N)ra   typingr   pydanticr   r   r   r   rL   r-   r\   rc   rS   rE   rC   <module>ri      s    G Gq! Q q Q	 q	
 
1 A a A a a   1 '("22  .) .bY  rE   