Ë
    LµCj  ã                   ó¶   — d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ  ed
¬«      Z ee«       ee«      fdedz  de	defd„Zy)aN  
Current-user dependency for JWT-protected endpoints.

Use `current_user: User = Depends(get_current_user)` on any endpoint
that should only be accessible to a logged-in customer (dashboard,
crop plans, notifications). This is distinct from `verify_api_key` in
app/core/security.py, which protects the machine-to-machine API surface.
é    )ÚDepends)ÚHTTPAuthorizationCredentialsÚ
HTTPBearer)Úselect)ÚAsyncSession)Údecode_token)ÚAuthenticationError)ÚUser)Úget_db_sessionF)Ú
auto_errorÚcredentialsNÚdbÚreturnc              ƒ   ó’  K  — | €t        d¬«      ‚t        | j                  d¬«      }|j                  d«      }|st        d¬«      ‚|j	                  t        t        «      j                  t        j                  |k(  «      «      ƒ d {  –—† }|j                  «       }|€t        d¬«      ‚|j                  st        d¬«      ‚|S 7 Œ<­w)	Nz'Authentication required. Please log in.)ÚmessageÚaccess)Úexpected_typeÚsubzInvalid token payloadzUser account no longer existsz3This account has been deactivated. Contact support.)r	   r   r   ÚgetÚexecuter   r
   ÚwhereÚidÚscalar_one_or_noneÚ	is_active)r   r   ÚpayloadÚuser_idÚresultÚusers         úBC:\Crop_Prediction\Backend\crop-ai-system\app\core\current_user.pyÚget_current_userr       s¯   è ø€ ð ÐÜ!Ð*SÔTÐTä˜;×2Ñ2À(ÔK€GØ�k‰k˜%Ó €GÙÜ!Ð*AÔBÐBà—:‘:œf¤T›l×0Ñ0´·±¸GÑ1CÓDÓE×E€FØ×$Ñ$Ó&€Dà€|Ü!Ð*IÔJÐJØ�>Š>Ü!Ð*_Ô`Ð`à€Kð Fús   ‚BCÂCÂ	=C)Ú__doc__Úfastapir   Úfastapi.securityr   r   Ú
sqlalchemyr   Úsqlalchemy.ext.asyncior   Úapp.core.auth_tokensr   Úapp.core.exceptionsr	   Úapp.db.modelsr
   Úapp.db.sessionr   Úbearer_schemer    © ó    r   ú<module>r-      sd   ðñõ ß EÝ Ý /å -Ý 3Ý Ý )á eÔ,€ñ 8?¸}Ó7MÙ˜~Ó.ñØ-°Ñ4ðàðð 
ôr,   