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

hub.exec.boto3.client.cloudfront.create_distribution
hub.exec.boto3.client.cloudfront.delete_distribution
hub.exec.boto3.client.cloudfront.get_distribution
hub.exec.boto3.client.cloudfront.list_distributions
hub.exec.boto3.client.cloudfront.update_distribution
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, distribution_config: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new web distribution. You create a CloudFront distribution to tell CloudFront where you want content
    to be delivered from, and the details about how to track and manage content delivery. Send a POST request to the
    /CloudFront API version/distribution/distribution ID resource.  When you update a distribution, there are more
    required fields than when you create a distribution. When you update your distribution by using
    UpdateDistribution, follow the steps included in the documentation to get the current configuration and then
    make your updates. This helps to make sure that you include all of the required fields. To view a summary, see
    Required Fields for Create Distribution and Update Distribution in the Amazon CloudFront Developer Guide.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.cloudfront.distribution.present:
                - name: value
                - distribution_config: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cloudfront.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_distribution(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudfront.create_distribution(
                ctx,
                
                
                **{"DistributionConfig": 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_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 distribution.

    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 distribution. For example:
            E2QWRUHAPOMQZL. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.cloudfront.distribution.absent:
                - name: value
                - id_: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cloudfront.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_distribution(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudfront.delete_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_distribution(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

