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

hub.exec.boto3.client.shield.create_protection
hub.exec.boto3.client.shield.delete_protection
hub.exec.boto3.client.shield.describe_protection
hub.exec.boto3.client.shield.list_protections
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, resource_arn: Text, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Enables Shield Advanced for a specific Amazon Web Services resource. The resource can be an Amazon CloudFront
    distribution, Elastic Load Balancing load balancer, Global Accelerator accelerator, Elastic IP Address, or an
    Amazon Route 53 hosted zone. You can add protection to only a single resource with each CreateProtection
    request. If you want to add protection to multiple resources at once, use the WAF console. For more information
    see Getting Started with Shield Advanced and Add Shield Advanced Protection to more Amazon Web Services
    Resources.

    Args:
        name(Text): Friendly name for the Protection you are creating.
        resource_arn(Text): The ARN (Amazon Resource Name) of the resource to be protected. The ARN should be in one of the
            following formats:   For an Application Load Balancer:
            arn:aws:elasticloadbalancing:region:account-id:loadbalancer/app/load-balancer-name/load-
            balancer-id     For an Elastic Load Balancer (Classic Load Balancer):
            arn:aws:elasticloadbalancing:region:account-id:loadbalancer/load-balancer-name     For an Amazon
            CloudFront distribution: arn:aws:cloudfront::account-id:distribution/distribution-id     For an
            Global Accelerator accelerator: arn:aws:globalaccelerator::account-id:accelerator/accelerator-id
            For Amazon Route 53: arn:aws:route53:::hostedzone/hosted-zone-id     For an Elastic IP address:
            arn:aws:ec2:region:account-id:eip-allocation/allocation-id.
        tags(List, optional): One or more tag key-value pairs for the Protection object that is created. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.shield.create_protection(
                ctx,
                
                
                **{"Name": name, "ResourceArn": resource_arn, "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.shield.describe_protection(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, protection_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an Shield Advanced Protection.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        protection_id(Text): The unique identifier (ID) for the Protection object to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

