
    j                     l    d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	m
Z
  G d de      Z G d d	e      Zy
)z$Mixins for common SDK functionality.    )annotations)ABCabstractmethod)Any)Fieldvalidate_callc                      e Zd ZU dZded<   ded<   edd       Zedd       Zedd       Zedd       Z	e	 	 	 	 dd	       Z
dd
Ze edd      f	 	 	 dd       ZddZe edd      f	 	 	 dd       ZddZy)MetadataConfigMixina  
    Mixin providing get/set/refresh methods for metadata and configuration.

    Classes using this mixin must implement:
    - _get_http_client() -> HTTPClientProtocol
    - _get_fetch_route() -> str
    - _get_update_route() -> str
    - _get_fetch_body() -> dict[str, Any]
    - _parse_response(data: dict[str, Any]) -> tuple[dict, dict]

    And must have these attributes:
    - _metadata: dict[str, object] | None
    - _configuration: dict[str, object] | None
    zdict[str, object] | None	_metadata_configurationc                     y)z(Get the HTTP client for making requests.N selfs    /home/cube/projects/richard/traning coach/.omo/evidence/nutricoach-v150-combined/st_01a0560c-r63-installed-wheel-first-claim-qa/venv/lib/python3.12/site-packages/honcho/mixins.py_get_http_clientz$MetadataConfigMixin._get_http_client        	    c                     yz2Get the route for fetching metadata/configuration.Nr   r   s    r   _get_fetch_routez$MetadataConfigMixin._get_fetch_route#   r   r   c                     yz2Get the route for updating metadata/configuration.Nr   r   s    r   _get_update_routez%MetadataConfigMixin._get_update_route(   r   r   c                     yz1Get the body for fetching metadata/configuration.Nr   r   s    r   _get_fetch_bodyz#MetadataConfigMixin._get_fetch_body-   r   r   c                     yz9Parse the response to extract metadata and configuration.Nr   r   datas     r   _parse_responsez#MetadataConfigMixin._parse_response2       
 	r   c                    | j                         j                  | j                         | j                               }| j	                  |      \  }}|| _        || _        | j
                  S )z
        Get metadata from the server and update the cache.

        Returns:
            A dictionary containing the metadata. Returns an empty dictionary
            if no metadata is set.
        bodyr   postr   r   r"   r   r   r   r!   metadataconfigurations       r   get_metadataz MetadataConfigMixin.get_metadata9   si     $$&++!!#$*>*>*@ , 
 #'"6"6t"<-!+~~r   .zMetadata dictionary to set)descriptionc                t    | j                         j                  | j                         d|i       || _        y)z
        Set metadata on the server and update the cache.

        Args:
            metadata: A dictionary of metadata to set.
                      Keys must be strings, values can be any JSON-serializable type.
        r*   r%   N)r   putr   r   r   r*   s     r   set_metadataz MetadataConfigMixin.set_metadataI   s=     	##""$h' 	$ 	
 "r   c                    | j                         j                  | j                         | j                               }| j	                  |      \  }}|| _        || _        | j                  S )z
        Get configuration from the server and update the cache.

        Returns:
            A dictionary containing the configuration. Returns an empty dictionary
            if no configuration is set.
        r%   r'   r)   s       r   get_configurationz%MetadataConfigMixin.get_configuration]   sk     $$&++!!#$*>*>*@ , 
 #'"6"6t"<-!+"""r   zConfiguration dictionary to setc                t    | j                         j                  | j                         d|i       || _        y)z
        Set configuration on the server and update the cache.

        Args:
            configuration: A dictionary of configuration to set.
                    Keys must be strings, values can be any JSON-serializable type.
        r+   r%   N)r   r/   r   r   r   r+   s     r   set_configurationz%MetadataConfigMixin.set_configurationm   s>     	##""$!=1 	$ 	
 ,r   c                    | j                         j                  | j                         | j                               }| j	                  |      \  }}|| _        || _        y)z
        Refresh cached metadata and configuration from the server.

        Makes a single API call to retrieve the latest metadata and configuration
        and updates the cached attributes.
        r%   Nr'   r)   s       r   refreshzMetadataConfigMixin.refresh   s_     $$&++!!#$*>*>*@ , 
 #'"6"6t"<-!+r   Nreturnr   r:   strr:   dict[str, Any]r!   r>   r:   z+tuple[dict[str, object], dict[str, object]]r:   dict[str, object]r*   rA   r:   Noner+   rA   r:   rC   r:   rC   )__name__
__module____qualname____doc____annotations__r   r   r   r   r   r"   r,   r   r   r1   r3   r6   r8   r   r   r   r
   r
      s    (',,        "	4    ',9'
"#"
 
" "&#   ,1>,
,(,
 
, ,&,r   r
   c                      e Zd ZdZedd       Zedd       Zedd       Zedd       Ze	 	 	 	 dd       Z	edd       Z
edd       Zedd	       Zedd
       ZddZddZddZddZddZy)AsyncMetadataConfigMixina  
    Async mixin providing get/set/refresh methods for metadata and configuration.

    Classes using this mixin must implement:
    - _get_async_http_client() -> AsyncHTTPClientProtocol
    - _get_fetch_route() -> str
    - _get_update_route() -> str
    - _get_fetch_body() -> dict[str, Any]
    - _parse_response(data: dict[str, Any]) -> tuple[dict, dict]
    - _set_metadata(metadata: dict[str, object]) -> None
    - _set_configuration(configuration: dict[str, object]) -> None
    c                     y)z.Get the async HTTP client for making requests.Nr   r   s    r   _get_async_http_clientz/AsyncMetadataConfigMixin._get_async_http_client   r   r   c                     yr   r   r   s    r   r   z)AsyncMetadataConfigMixin._get_fetch_route   r   r   c                     yr   r   r   s    r   r   z*AsyncMetadataConfigMixin._get_update_route   r   r   c                     yr   r   r   s    r   r   z(AsyncMetadataConfigMixin._get_fetch_body   r   r   c                     yr   r   r    s     r   r"   z(AsyncMetadataConfigMixin._parse_response   r#   r   c                     y)z"Set metadata on the parent object.Nr   r0   s     r   _set_metadataz&AsyncMetadataConfigMixin._set_metadata   r   r   c                     y)z'Set configuration on the parent object.Nr   r5   s     r   _set_configurationz+AsyncMetadataConfigMixin._set_configuration   r   r   c                     y)z+Get cached metadata from the parent object.Nr   r   s    r   _get_metadataz&AsyncMetadataConfigMixin._get_metadata   r   r   c                     y)z0Get cached configuration from the parent object.Nr   r   s    r   _get_configurationz+AsyncMetadataConfigMixin._get_configuration   r   r   c                $  K   | j                         j                  | j                         | j                                d{   }| j	                  |      \  }}| j                  |       | j                  |       | j                         S 7 Jw)z,Get metadata from the server asynchronously.r%   N)rN   r(   r   r   r"   rT   rV   rX   r)   s       r   r,   z%AsyncMetadataConfigMixin.get_metadata   s     00277!!#$*>*>*@ 8 
 
 #'"6"6t"<-8$.!!##
   ABBABc                   K   | j                         j                  | j                         d|i       d{    | j                  |       y7 w)z*Set metadata on the server asynchronously.r*   r%   N)rN   r/   r   rT   r0   s     r   r1   z%AsyncMetadataConfigMixin.set_metadata   sU     ))+//""$h' 0 
 	
 	
 	8$		
   5AAAc                $  K   | j                         j                  | j                         | j                                d{   }| j	                  |      \  }}| j                  |       | j                  |       | j                         S 7 Jw)z1Get configuration from the server asynchronously.r%   N)rN   r(   r   r   r"   rT   rV   rZ   r)   s       r   r3   z*AsyncMetadataConfigMixin.get_configuration   s     00277!!#$*>*>*@ 8 
 
 #'"6"6t"<-8$.&&((
r\   c                   K   | j                         j                  | j                         d|i       d{    | j                  |       y7 w)z/Set configuration on the server asynchronously.r+   r%   N)rN   r/   r   rV   r5   s     r   r6   z*AsyncMetadataConfigMixin.set_configuration   sU     ))+//""$!=1 0 
 	
 	
 	.		
r^   c                  K   | j                         j                  | j                         | j                                d{   }| j	                  |      \  }}| j                  |       | j                  |       y7 ;w)z9Refresh cached metadata and configuration asynchronously.r%   N)rN   r(   r   r   r"   rT   rV   r)   s       r   r8   z AsyncMetadataConfigMixin.refresh   sx     00277!!#$*>*>*@ 8 
 
 #'"6"6t"<-8$.
s   ABA?<BNr9   r;   r=   r?   rB   rD   r@   rE   )rF   rG   rH   rI   r   rN   r   r   r   r"   rT   rV   rX   rZ   r,   r1   r3   r6   r8   r   r   r   rL   rL      s             "	4         $%)//r   rL   N)rI   
__future__r   abcr   r   typingr   pydanticr   r   r
   rL   r   r   r   <module>rf      s1    * " #  )B,# B,Jh/s h/r   