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

hub.exec.boto3.client.cloudfront.create_monitoring_subscription
hub.exec.boto3.client.cloudfront.delete_monitoring_subscription
hub.exec.boto3.client.cloudfront.get_monitoring_subscription
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, distribution_id: Text, monitoring_subscription: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Enables additional CloudWatch metrics for the specified CloudFront distribution. The additional metrics incur an
    additional cost. For more information, see Viewing additional CloudFront distribution metrics in the Amazon
    CloudFront Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        distribution_id(Text): The ID of the distribution that you are enabling metrics for.
        monitoring_subscription(Dict): A monitoring subscription. This structure contains information about whether additional
            CloudWatch metrics are enabled for a given CloudFront distribution.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudfront.create_monitoring_subscription(
                ctx,
                
                
                **{"DistributionId": distribution_id, "MonitoringSubscription": monitoring_subscription}
            )
            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_monitoring_subscription(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, distribution_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Disables additional CloudWatch metrics for the specified CloudFront distribution.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        distribution_id(Text): The ID of the distribution that you are disabling metrics for.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

