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

hub.exec.boto3.client.guardduty.create_detector
hub.exec.boto3.client.guardduty.delete_detector
hub.exec.boto3.client.guardduty.get_detector
hub.exec.boto3.client.guardduty.list_detectors
hub.exec.boto3.client.guardduty.update_detector
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, enable: bool, finding_publishing_frequency: Text = None, data_sources: Dict = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a single Amazon GuardDuty detector. A detector is a resource that represents the GuardDuty service. To
    start using GuardDuty, you must create a detector in each Region where you enable the service. You can have only
    one detector per account per Region. All data sources are enabled in a new detector by default.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        enable(bool): A Boolean value that specifies whether the detector is to be enabled.
        finding_publishing_frequency(Text, optional): A value that specifies how frequently updated findings are exported. Defaults to None.
        data_sources(Dict, optional): Describes which data sources will be enabled for the detector. Defaults to None.
        tags(Dict, optional): The tags to be added to a new detector resource. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.guardduty.create_detector(
                ctx,
                
                ClientToken=name,
                **{"Enable": enable, "FindingPublishingFrequency": finding_publishing_frequency, "DataSources": data_sources, "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_detector(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, detector_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an Amazon GuardDuty detector that is specified by the detector 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 you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

