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

hub.exec.boto3.client.ram.associate_resource_share_permission
hub.exec.boto3.client.ram.disassociate_resource_share_permission
hub.exec.boto3.client.ram.list_resource_share_permissions
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, resource_share_arn: Text, permission_arn: Text, replace: bool = None, client_token: Text = None, permission_version: int = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Associates a permission with a resource share.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resource_share_arn(Text): The Amazon Resource Name (ARN) of the resource share.
        permission_arn(Text): The Amazon Resource Name (ARN) of the AWS RAM permissions to associate with the resource share.
        replace(bool, optional): Indicates whether the permission should replace the permissions that are currently associated
            with the resource share. Use true to replace the current permissions. Use false to add the
            permission to the current permission. Defaults to None.
        client_token(Text, optional): A unique, case-sensitive identifier that you provide to ensure the idempotency of the request. Defaults to None.
        permission_version(int, optional): The version of the AWS RAM permissions to associate with the resource share. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ram.associate_resource_share_permission(
                ctx,
                
                
                **{"resourceShareArn": resource_share_arn, "permissionArn": permission_arn, "replace": replace, "clientToken": client_token, "permissionVersion": permission_version}
            )
            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.ram.list_resource_share_permissions(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, resource_share_arn: Text, permission_arn: Text, client_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Disassociates an AWS RAM permission from a resource share.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resource_share_arn(Text): The Amazon Resource Name (ARN) of the resource share.
        permission_arn(Text): The ARN of the permission to disassociate from the resource share.
        client_token(Text, optional): A unique, case-sensitive identifier that you provide to ensure the idempotency of the request. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.ram.disassociate_resource_share_permission(
                ctx,
                
                
                **{"resourceShareArn": resource_share_arn, "permissionArn": permission_arn, "clientToken": client_token}
            )
            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.ram.list_resource_share_permissions(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

