"""
Autogenerated state module using `pop-create-idem <https://gitlab.com/saltstack/pop/pop-create-idem>`__

hub.exec.boto3.client.cloudfront.create_streaming_distribution
hub.exec.boto3.client.cloudfront.delete_streaming_distribution
hub.exec.boto3.client.cloudfront.get_streaming_distribution
hub.exec.boto3.client.cloudfront.list_streaming_distributions
hub.exec.boto3.client.cloudfront.update_streaming_distribution
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, streaming_distribution_config: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    This API is deprecated. Amazon CloudFront is deprecating real-time messaging protocol (RTMP) distributions on
    December 31, 2020. For more information, read the announcement on the Amazon CloudFront discussion forum.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        streaming_distribution_config(Dict): The streaming distribution's configuration information.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.cloudfront.streaming_distribution.present:
                - name: value
                - streaming_distribution_config: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cloudfront.streaming_distribution.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    
    before = await hub.exec.boto3.client.cloudfront.get_streaming_distribution(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudfront.create_streaming_distribution(
                ctx,
                
                
                **{"StreamingDistributionConfig": streaming_distribution_config}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            ret["comment"] = f"Created '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    
    # TODO perform other modifications as needed here
    ...

    after = await hub.exec.boto3.client.cloudfront.get_streaming_distribution(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, id_: Text, if_match: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Delete a streaming distribution. To delete an RTMP distribution using the CloudFront API, perform the following
    steps.  To delete an RTMP distribution using the CloudFront API:   Disable the RTMP distribution.   Submit a GET
    Streaming Distribution Config request to get the current configuration and the Etag header for the distribution.
    Update the XML document that was returned in the response to your GET Streaming Distribution Config request to
    change the value of Enabled to false.   Submit a PUT Streaming Distribution Config request to update the
    configuration for your distribution. In the request body, include the XML document that you updated in Step 3.
    Then set the value of the HTTP If-Match header to the value of the ETag header that CloudFront returned when you
    submitted the GET Streaming Distribution Config request in Step 2.   Review the response to the PUT Streaming
    Distribution Config request to confirm that the distribution was successfully disabled.   Submit a GET Streaming
    Distribution Config request to confirm that your changes have propagated. When propagation is complete, the
    value of Status is Deployed.   Submit a DELETE Streaming Distribution request. Set the value of the HTTP If-
    Match header to the value of the ETag header that CloudFront returned when you submitted the GET Streaming
    Distribution Config request in Step 2.   Review the response to your DELETE Streaming Distribution request to
    confirm that the distribution was successfully deleted.   For information about deleting a distribution using
    the CloudFront console, see Deleting a Distribution in the Amazon CloudFront Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The distribution ID.
        if_match(Text, optional): The value of the ETag header that you received when you disabled the streaming distribution. For
            example: E2QWRUHAPOMQZL. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.cloudfront.streaming_distribution.absent:
                - name: value
                - id_: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cloudfront.streaming_distribution.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    

    before = await hub.exec.boto3.client.cloudfront.get_streaming_distribution(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudfront.delete_streaming_distribution(
                ctx,
                
                
                **{"Id": id_, "IfMatch": if_match}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            result["comment"] = f"Deleted '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    

    after = await hub.exec.boto3.client.cloudfront.get_streaming_distribution(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

