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

hub.exec.boto3.client.guardduty.create_threat_intel_set
hub.exec.boto3.client.guardduty.delete_threat_intel_set
hub.exec.boto3.client.guardduty.get_threat_intel_set
hub.exec.boto3.client.guardduty.list_threat_intel_sets
hub.exec.boto3.client.guardduty.update_threat_intel_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 ThreatIntelSet. ThreatIntelSets consist of known malicious IP addresses. GuardDuty generates
    findings based on ThreatIntelSets. Only users of the administrator account can use this operation.

    Args:
        name(Text): A user-friendly ThreatIntelSet name displayed in all findings that are generated by activity
            that involves IP addresses included in this ThreatIntelSet.
        detector_id(Text): The unique ID of the detector of the GuardDuty account that you want to create a threatIntelSet
            for.
        format_(Text): The format of the file that contains the ThreatIntelSet.
        location(Text): The URI of the file that contains the ThreatIntelSet. 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 ThreatIntelSet.
        tags(Dict, optional): The tags to be added to a new threat list resource. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.guardduty.threat_intel_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.threat_intel_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_threat_intel_set(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.guardduty.create_threat_intel_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_threat_intel_set(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, detector_id: Text, threat_intel_set_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the ThreatIntelSet specified by the ThreatIntelSet ID.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        detector_id(Text): The unique ID of the detector that the threatIntelSet is associated with.
        threat_intel_set_id(Text): The unique ID of the threatIntelSet that you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

