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

hub.exec.boto3.client.logs.delete_destination
hub.exec.boto3.client.logs.describe_destinations
hub.exec.boto3.client.logs.put_destination
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, destination_name: Text, target_arn: Text, role_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates or updates a destination. This operation is used only to create destinations for cross-account
    subscriptions. A destination encapsulates a physical resource (such as an Amazon Kinesis stream) and enables you
    to subscribe to a real-time stream of log events for a different account, ingested using PutLogEvents. Through
    an access policy, a destination controls what is written to it. By default, PutDestination does not set any
    access policy with the destination, which means a cross-account user cannot call PutSubscriptionFilter against
    this destination. To enable this, the destination owner must call PutDestinationPolicy after PutDestination. To
    perform a PutDestination operation, you must also have the iam:PassRole permission.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        destination_name(Text): A name for the destination.
        target_arn(Text): The ARN of an Amazon Kinesis stream to which to deliver matching log events.
        role_arn(Text): The ARN of an IAM role that grants CloudWatch Logs permissions to call the Amazon Kinesis
            PutRecord operation on the destination stream.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.logs.destination.present:
                - name: value
                - destination_name: value
                - target_arn: value
                - role_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.logs.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.logs.describe_destinations(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.logs.put_destination(
                ctx,
                
                
                **{"destinationName": destination_name, "targetArn": target_arn, "roleArn": role_arn}
            )
            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.logs.describe_destinations(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, destination_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified destination, and eventually disables all the subscription filters that publish to it. This
    operation does not delete the physical resource encapsulated by the destination.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        destination_name(Text): The name of the destination.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

