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

hub.exec.boto3.client.guardduty.create_ip_set
hub.exec.boto3.client.guardduty.delete_ip_set
hub.exec.boto3.client.guardduty.get_ip_set
hub.exec.boto3.client.guardduty.list_ip_sets
hub.exec.boto3.client.guardduty.update_ip_set
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, detector_id: Text, format_: Text, location: Text, activate: bool, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new IPSet, which is called a trusted IP list in the console user interface. An IPSet is a list of IP
    addresses that are trusted for secure communication with AWS infrastructure and applications. GuardDuty doesn't
    generate findings for IP addresses that are included in IPSets. Only users from the administrator account can
    use this operation.

    Args:
        name(Text): The user-friendly name to identify the IPSet.  Allowed characters are alphanumerics, spaces,
            hyphens (-), and underscores (_).
        detector_id(Text): The unique ID of the detector of the GuardDuty account that you want to create an IPSet for.
        format_(Text): The format of the file that contains the IPSet.
        location(Text): The URI of the file that contains the IPSet. For example: https://s3.us-west-2.amazonaws.com/my-
            bucket/my-object-key.
        activate(bool): A Boolean value that indicates whether GuardDuty is to start using the uploaded IPSet.
        tags(Dict, optional): The tags to be added to a new IP set resource. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.guardduty.ip_set.present:
                - name: value
                - detector_id: value
                - format_: value
                - location: value
                - activate: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.guardduty.ip_set.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.guardduty.get_ip_set(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.guardduty.create_ip_set(
                ctx,
                
                ClientToken=name,
                **{"Name": name, "DetectorId": detector_id, "Format": format_, "Location": location, "Activate": activate, "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.guardduty.get_ip_set(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, detector_id: Text, ip_set_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the IPSet specified by the ipSetId. IPSets are called trusted IP lists in the console user interface.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        detector_id(Text): The unique ID of the detector associated with the IPSet.
        ip_set_id(Text): The unique ID of the IPSet to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.guardduty.delete_ip_set(
                ctx,
                
                
                **{"DetectorId": detector_id, "IpSetId": ip_set_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.guardduty.get_ip_set(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

