o
    i                  	   @   sJ   d dl mZ d dlmZmZmZmZmZmZ G dd deeeeeeZ	dS )    )force_to_epoch_seconds)GetableAPIResourceCreateableAPIResourceUpdatableAPIResourceListableAPIResourceDeletableAPIResourceActionAPIResourcec                       s   e Zd ZdZdZed fdd	Ze fdd	Zed fdd	Zed fdd	Z	e fddZ
e fddZe fddZe fddZe fddZe fddZ  ZS )ServiceLevelObjectivez<
    A wrapper around Service Level Objective HTTP API.
    sloFPOSTNc                    s    t t| jdddd|d|S )zE
        Create a SLO

        :returns: created SLO details
        Fr   N)attach_host_namemethodidparams )superr	   create)clsr   r   r   r   body	__class__r   X/home/ubuntu/.local/lib/python3.10/site-packages/datadog/api/service_level_objectives.pyr      s
   zServiceLevelObjective.createc                       t t| j|fi |S )z
        Get a specific SLO details.

        :param id: SLO id to get details for
        :type id: str

        :returns: SLO details
        )r   r	   getr   r   r   r   r   r   r   (      
zServiceLevelObjective.getr   d   c           	         sZ   i }|r||d< |r||d< |r||d< |r||d< ||d< ||d< t t| jdi |S )	a  
        Get all SLO details.

        :param query: optional search query to filter results for SLO name
        :type query: str

        :param tags_query: optional search query to filter results for a single SLO tag
        :type query: str

        :param metrics_query: optional search query to filter results based on SLO numerator and denominator
        :type query: str

        :param ids: optional list of SLO ids to get many specific SLOs at once.
        :type ids: list(str)

        :param offset: offset of results to use (default 0)
        :type offset: int

        :param limit: limit of results to return (default: 100)
        :type limit: int

        :returns: SLOs matching the query
        queryids
tags_querymetrics_queryoffsetlimitNr   )r   r	   get_all)	r   r   r   r    r   r!   r"   r   search_termsr   r   r   r#   4   s   zServiceLevelObjective.get_allc                    s   t t| j||fi |S )z
        Update a specific SLO details.

        :param id: SLO id to update details for
        :type id: str

        :returns: SLO details
        )r   r	   update)r   r   r   r   r   r   r   r%   [   s   
zServiceLevelObjective.updatec                    r   )z
        Delete a specific SLO.

        :param id: SLO id to delete
        :type id: str

        :returns: SLO ids removed
        )r   r	   deleter   r   r   r   r&   g   r   zServiceLevelObjective.deletec                    s   t t| jdd||dgdS )aL  
        Bulk Delete Timeframes from multiple SLOs.

        :param ops: a dictionary mapping of SLO ID to timeframes to remove.
        :type ops: dict(str, list(str))

        :returns: Dictionary representing the API's JSON response
            `errors` - errors with operation
            `data` - updates and deletions
        r   bulk_delete   )r   r   !suppress_response_errors_on_codesr   r	   _trigger_class_action)r   opsr   r   r   r   r'   s   s   
z!ServiceLevelObjective.bulk_deletec                    s    t t| jdd|d|idgdS )z
        Delete Multiple SLOs

        :param ids: a list of SLO IDs to remove
        :type ids: list(str)

        :returns: Dictionary representing the API's JSON response see `data` list(slo ids) && `errors`
        DELETE r   r(   r   r   r)   r*   r   r   r   r   r   r   delete_many   s   

z!ServiceLevelObjective.delete_manyc                    s$   ||d< t t| jdd|ddgdS )a  
        Check if the following SLOs can be safely deleted.

        This is used to check if SLO has any references to it.

        :param ids: a list of SLO IDs to check
        :type ids: list(str)

        :returns: Dictionary representing the API's JSON response
                  "data.ok" represents a list of SLO ids that have no known references.
                  "errors" contains a dictionary of SLO ID to known reference(s).
        r   GET
can_deleteNr(   r/   r*   r0   r   r   r   r3      s   
z ServiceLevelObjective.can_deletec                    s>   ||d< t ||d< t ||d< tt| jdd||ddgdS )	aZ  
        Get the SLO's history from the given time range.

        :param id: SLO ID to query
        :type id: str

        :param from_ts: `from` timestamp in epoch seconds to query
        :type from_ts: int|datetime.datetime

        :param to_ts: `to` timestamp in epoch seconds to query, must be > `from_ts`
        :type to_ts: int|datetime.datetime

        :returns: Dictionary representing the API's JSON response
                  "data.ok" represents a list of SLO ids that have no known references.
                  "errors" contains a dictionary of SLO ID to known reference(s).
        r   from_tsto_tsr2   historyNr(   )r   r   r   r)   )r   r   r	   r+   )r   r   r4   r5   r   r   r   r   r6      s   
zServiceLevelObjective.historyc                    s   t t| jdd|dS )za
        Search SLOs.

        :returns: Dictionary representing the API's JSON response
        r2   search)r   r*   )r   r   r   r   r   r7      s   zServiceLevelObjective.search)Fr   NN)NNNNr   r   )N)__name__
__module____qualname____doc___resource_nameclassmethodr   r   r#   r%   r&   r'   r1   r3   r6   r7   __classcell__r   r   r   r   r	      s.    
&r	   N)
datadog.util.formatr   datadog.api.resourcesr   r   r   r   r   r   r	   r   r   r   r   <module>   s    

