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

hub.exec.boto3.client.lexv2_models.create_resource_policy
hub.exec.boto3.client.lexv2_models.delete_resource_policy
hub.exec.boto3.client.lexv2_models.describe_resource_policy
hub.exec.boto3.client.lexv2_models.update_resource_policy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, resource_arn: Text, policy: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new resource policy with the specified policy statements.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resource_arn(Text): The Amazon Resource Name (ARN) of the bot or bot alias that the resource policy is attached to.
        policy(Text): A resource policy to add to the resource. The policy is a JSON structure that contains one or
            more statements that define the policy. The policy must follow the IAM syntax. For more
            information about the contents of a JSON policy document, see  IAM JSON policy reference .  If
            the policy isn't valid, Amazon Lex returns a validation exception.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lexv2_models.create_resource_policy(
                ctx,
                
                
                **{"resourceArn": resource_arn, "policy": policy}
            )
            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.lexv2_models.describe_resource_policy(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, resource_arn: Text, expected_revision_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes an existing policy from a bot or bot alias. If the resource doesn't have a policy attached, Amazon Lex
    returns an exception.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resource_arn(Text): The Amazon Resource Name (ARN) of the bot or bot alias that has the resource policy attached.
        expected_revision_id(Text, optional): The identifier of the revision to edit. If this ID doesn't match the current revision number,
            Amazon Lex returns an exception If you don't specify a revision ID, Amazon Lex will delete the
            current policy. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

