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

hub.exec.boto3.client.shield.create_protection_group
hub.exec.boto3.client.shield.delete_protection_group
hub.exec.boto3.client.shield.describe_protection_group
hub.exec.boto3.client.shield.list_protection_groups
hub.exec.boto3.client.shield.update_protection_group
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, protection_group_id: Text, aggregation: Text, pattern: Text, resource_type: Text = None, members: List = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a grouping of protected resources so they can be handled as a collective. This resource grouping
    improves the accuracy of detection and reduces false positives.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        protection_group_id(Text): The name of the protection group. You use this to identify the protection group in lists and to
            manage the protection group, for example to update, delete, or describe it.
        aggregation(Text): Defines how Shield combines resource data for the group in order to detect, mitigate, and report
            events.   Sum - Use the total traffic across the group. This is a good choice for most cases.
            Examples include Elastic IP addresses for EC2 instances that scale manually or automatically.
            Mean - Use the average of the traffic across the group. This is a good choice for resources that
            share traffic uniformly. Examples include accelerators and load balancers.   Max - Use the
            highest traffic from each resource. This is useful for resources that don't share traffic and
            for resources that share that traffic in a non-uniform way. Examples include Amazon CloudFront
            and origin resources for CloudFront distributions.
        pattern(Text): The criteria to use to choose the protected resources for inclusion in the group. You can
            include all resources that have protections, provide a list of resource Amazon Resource Names
            (ARNs), or include all resources of a specified resource type.
        resource_type(Text, optional): The resource type to include in the protection group. All protected resources of this type are
            included in the protection group. Newly protected resources of this type are automatically added
            to the group. You must set this when you set Pattern to BY_RESOURCE_TYPE and you must not set it
            for any other Pattern setting. Defaults to None.
        members(List, optional): The Amazon Resource Names (ARNs) of the resources to include in the protection group. You must
            set this when you set Pattern to ARBITRARY and you must not set it for any other Pattern
            setting. Defaults to None.
        tags(List, optional): One or more tag key-value pairs for the protection group. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.shield.create_protection_group(
                ctx,
                
                
                **{"ProtectionGroupId": protection_group_id, "Aggregation": aggregation, "Pattern": pattern, "ResourceType": resource_type, "Members": members, "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_group(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, protection_group_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes the specified protection group.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        protection_group_id(Text): The name of the protection group. You use this to identify the protection group in lists and to
            manage the protection group, for example to update, delete, or describe it.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

