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

hub.exec.boto3.client.logs.delete_resource_policy
hub.exec.boto3.client.logs.describe_resource_policies
hub.exec.boto3.client.logs.put_resource_policy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, policy_name: Text = None, policy_document: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates or updates a resource policy allowing other Amazon Web Services services to put log events to this
    account, such as Amazon Route 53. An account can have up to 10 resource policies per Amazon Web Services Region.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        policy_name(Text, optional): Name of the new policy. This parameter is required. Defaults to None.
        policy_document(Text, optional): Details of the new policy, including the identity of the principal that is enabled to put logs
            to this account. This is formatted as a JSON string. This parameter is required. The following
            example creates a resource policy enabling the Route 53 service to put DNS query logs in to the
            specified log group. Replace "logArn" with the ARN of your CloudWatch Logs resource, such as a
            log group or log stream. CloudWatch Logs also supports aws:SourceArn and aws:SourceAccount
            condition context keys. In the example resource policy, you would replace the value of SourceArn
            with the resource making the call from Route 53 to CloudWatch Logs and replace the value of
            SourceAccount with the Amazon Web Services account ID making that call.   { "Version":
            "2012-10-17", "Statement": [ { "Sid": "Route53LogsToCloudWatchLogs", "Effect": "Allow",
            "Principal": { "Service": [ "route53.amazonaws.com" ] }, "Action": "logs:PutLogEvents",
            "Resource": "logArn", "Condition": { "ArnLike": { "aws:SourceArn": "myRoute53ResourceArn" },
            "StringEquals": { "aws:SourceAccount": "myAwsAccountId" } } } ] }. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.logs.put_resource_policy(
                ctx,
                
                
                **{"policyName": policy_name, "policyDocument": policy_document}
            )
            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_resource_policies(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, policy_name: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a resource policy from this account. This revokes the access of the identities in that policy to put log
    events to this account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        policy_name(Text, optional): The name of the policy to be revoked. This parameter is required. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

