o
    z­j´  ã                   @   s\   d dl mZmZmZ d dlmZmZ d dlmZm	Z	 eƒ Z
e
jdedd�defdd	„ƒZd
S )é    )Ú	APIRouterÚDependsÚHTTPException)Ú
YieldInputÚYieldPredictionResponse)Úpredict_yieldÚget_weather_dataz/predictéÈ   )Úresponse_modelÚstatus_codeÚyield_inputc              
   Ã   s¾   �z?| j r| js| j | _d}t| dƒr%t| dƒr%| jr%| jr%t| j| jƒ}t| ƒ\}}}d|||dœ}|r9||d< tdi |¤ŽW S  ty^ } zt	d|› �ƒ t
dd	t|ƒ› �d
�‚d}~ww )zT
    Receives farm details and returns a yield prediction with recommendations.
    NÚlatitudeÚ	longitudeT)ÚsuccessÚyield_Úestimated_productionÚrecommendationsÚweather_dataz'Unexpected error in /predict endpoint: iô  zIAn internal server error occurred while generating the yield prediction: )r   Údetail© )Ú	crop_typeÚcropÚhasattrr   r   r   r   r   Ú	ExceptionÚprintr   Ústr)r   r   Úyield_per_hectareÚtotal_productionr   Úresponse_dataÚer   r   úC/var/www/html/CropPilot/backend/app/api/endpoints/yield_endpoint.pyÚpredict_farm_yield   s2   €ÿÿü€ýr!   N)Úfastapir   r   r   Úapp.models.yield_modelr   r   Ú%app.services.yield_prediction_servicer   r   ÚrouterÚpostr!   r   r   r   r    Ú<module>   s    ÿ