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

hub.exec.boto3.client.wellarchitected.create_workload_share
hub.exec.boto3.client.wellarchitected.delete_workload_share
hub.exec.boto3.client.wellarchitected.list_workload_shares
hub.exec.boto3.client.wellarchitected.update_workload_share
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, workload_id: Text, shared_with: Text, permission_type: Text, client_request_token: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create a workload share. The owner of a workload can share it with other AWS accounts and IAM users in the same
    AWS Region. Shared access to a workload is not removed until the workload invitation is deleted. For more
    information, see Sharing a Workload in the AWS Well-Architected Tool User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        workload_id(Text): The ID assigned to the workload. This ID is unique within an AWS Region.
        shared_with(Text): The AWS account ID or IAM role with which the workload is shared.
        permission_type(Text): Permission granted on a workload share.
        client_request_token(Text): A unique case-sensitive string used to ensure that this request is idempotent (executes only
            once). You should not reuse the same token for other requests. If you retry a request with the
            same client request token and the same parameters after it has completed successfully, the
            result of the original request is returned.   This token is listed as required, however, if you
            do not specify it, the AWS SDKs automatically generate one for you. If you are not using the AWS
            SDK or the AWS CLI, you must provide this token or the request will fail.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.wellarchitected.workload_share.present:
                - name: value
                - workload_id: value
                - shared_with: value
                - permission_type: value
                - client_request_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.wellarchitected.workload_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.wellarchitected.list_workload_shares(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.wellarchitected.create_workload_share(
                ctx,
                
                
                **{"WorkloadId": workload_id, "SharedWith": shared_with, "PermissionType": permission_type, "ClientRequestToken": client_request_token}
            )
            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.wellarchitected.list_workload_shares(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, share_id: Text, workload_id: Text, client_request_token: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Delete a workload share.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        share_id(Text): The ID associated with the workload share.
        workload_id(Text): The ID assigned to the workload. This ID is unique within an AWS Region.
        client_request_token(Text): A unique case-sensitive string used to ensure that this request is idempotent (executes only
            once). You should not reuse the same token for other requests. If you retry a request with the
            same client request token and the same parameters after it has completed successfully, the
            result of the original request is returned.   This token is listed as required, however, if you
            do not specify it, the AWS SDKs automatically generate one for you. If you are not using the AWS
            SDK or the AWS CLI, you must provide this token or the request will fail.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.wellarchitected.workload_share.absent:
                - name: value
                - share_id: value
                - workload_id: value
                - client_request_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.wellarchitected.workload_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.wellarchitected.list_workload_shares(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.wellarchitected.delete_workload_share(
                ctx,
                
                
                **{"ShareId": share_id, "WorkloadId": workload_id, "ClientRequestToken": client_request_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.wellarchitected.list_workload_shares(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

