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

hub.exec.boto3.client.guardduty.create_publishing_destination
hub.exec.boto3.client.guardduty.delete_publishing_destination
hub.exec.boto3.client.guardduty.describe_publishing_destination
hub.exec.boto3.client.guardduty.list_publishing_destinations
hub.exec.boto3.client.guardduty.update_publishing_destination
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, detector_id: Text, destination_type: Text, destination_properties: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a publishing destination to export findings to. The resource to export findings to must exist before you
    use this operation.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        detector_id(Text): The ID of the GuardDuty detector associated with the publishing destination.
        destination_type(Text): The type of resource for the publishing destination. Currently only Amazon S3 buckets are
            supported.
        destination_properties(Dict): The properties of the publishing destination, including the ARNs for the destination and the KMS
            key used for encryption.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.guardduty.create_publishing_destination(
                ctx,
                
                ClientToken=name,
                **{"DetectorId": detector_id, "DestinationType": destination_type, "DestinationProperties": destination_properties}
            )
            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.describe_publishing_destination(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, detector_id: Text, destination_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the publishing definition with the specified destinationId.

    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 publishing destination to delete.
        destination_id(Text): The ID of the publishing destination to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

