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

hub.exec.boto3.client.lightsail.create_distribution
hub.exec.boto3.client.lightsail.delete_distribution
hub.exec.boto3.client.lightsail.get_distributions
hub.exec.boto3.client.lightsail.update_distribution
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, distribution_name: Text, origin: Dict, default_cache_behavior: Dict, bundle_id: Text, cache_behavior_settings: Dict = None, cache_behaviors: List = None, ip_address_type: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an Amazon Lightsail content delivery network (CDN) distribution. A distribution is a globally
    distributed network of caching servers that improve the performance of your website or web application hosted on
    a Lightsail instance. For more information, see Content delivery networks in Amazon Lightsail.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        distribution_name(Text): The name for the distribution.
        origin(Dict): An object that describes the origin resource for the distribution, such as a Lightsail instance
            or load balancer. The distribution pulls, caches, and serves content from the origin.
        default_cache_behavior(Dict): An object that describes the default cache behavior for the distribution.
        cache_behavior_settings(Dict, optional): An object that describes the cache behavior settings for the distribution. Defaults to None.
        cache_behaviors(List, optional): An array of objects that describe the per-path cache behavior for the distribution. Defaults to None.
        bundle_id(Text): The bundle ID to use for the distribution. A distribution bundle describes the specifications of
            your distribution, such as the monthly cost and monthly network transfer quota. Use the
            GetDistributionBundles action to get a list of distribution bundle IDs that you can specify.
        ip_address_type(Text, optional): The IP address type for the distribution. The possible values are ipv4 for IPv4 only, and
            dualstack for IPv4 and IPv6. The default value is dualstack. Defaults to None.
        tags(List, optional): The tag keys and optional values to add to the distribution during create. Use the TagResource
            action to tag a resource after it's created. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.lightsail.distribution.present:
                - name: value
                - distribution_name: value
                - origin: value
                - default_cache_behavior: value
                - bundle_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.lightsail.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.lightsail.get_distributions(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lightsail.create_distribution(
                ctx,
                
                
                **{"distributionName": distribution_name, "origin": origin, "defaultCacheBehavior": default_cache_behavior, "cacheBehaviorSettings": cache_behavior_settings, "cacheBehaviors": cache_behaviors, "bundleId": bundle_id, "ipAddressType": ip_address_type, "tags": tags}
            )
            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.lightsail.get_distributions(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, distribution_name: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes your Amazon Lightsail content delivery network (CDN) distribution.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        distribution_name(Text, optional): The name of the distribution to delete. Use the GetDistributions action to get a list of
            distribution names that you can specify. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

