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

hub.exec.boto3.client.ram.associate_resource_share
hub.exec.boto3.client.ram.create_resource_share
hub.exec.boto3.client.ram.delete_resource_share
hub.exec.boto3.client.ram.disassociate_resource_share
hub.exec.boto3.client.ram.get_resource_shares
hub.exec.boto3.client.ram.update_resource_share
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, resource_arns: List = None, principals: List = None, tags: List = None, allow_external_principals: bool = None, client_token: Text = None, permission_arns: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a resource share.

    Args:
        name(Text): The name of the resource share.
        resource_arns(List, optional): The Amazon Resource Names (ARN) of the resources to associate with the resource share. Defaults to None.
        principals(List, optional): The principals to associate with the resource share. The possible values are IDs of AWS
            accounts, the ARN of an OU or organization from AWS Organizations. Defaults to None.
        tags(List, optional): One or more tags. Defaults to None.
        allow_external_principals(bool, optional): Indicates whether principals outside your AWS organization can be associated with a resource
            share. 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_arns(List, optional): The ARNs of the permissions to associate with the resource share. If you do not specify an ARN
            for the permission, AWS RAM automatically attaches the default version of the permission for
            each resource type. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ram.create_resource_share(
                ctx,
                
                
                **{"Name": name, "resourceArns": resource_arns, "principals": principals, "tags": tags, "allowExternalPrincipals": allow_external_principals, "clientToken": client_token, "permissionArns": permission_arns}
            )
            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.get_resource_shares(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, resource_share_arn: Text, client_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified 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.
        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.absent:
                - name: value
                - resource_share_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ram.resource_share.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.get_resource_shares(name)

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

