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

hub.exec.boto3.client.iotsitewise.create_access_policy
hub.exec.boto3.client.iotsitewise.delete_access_policy
hub.exec.boto3.client.iotsitewise.describe_access_policy
hub.exec.boto3.client.iotsitewise.list_access_policies
hub.exec.boto3.client.iotsitewise.update_access_policy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, access_policy_identity: Dict, access_policy_resource: Dict, access_policy_permission: Text, client_token: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an access policy that grants the specified identity (Amazon Web Services SSO user, Amazon Web Services
    SSO group, or IAM user) access to the specified IoT SiteWise Monitor portal or project resource.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        access_policy_identity(Dict): The identity for this access policy. Choose an Amazon Web Services SSO user, an Amazon Web
            Services SSO group, or an IAM user.
        access_policy_resource(Dict): The IoT SiteWise Monitor resource for this access policy. Choose either a portal or a project.
        access_policy_permission(Text): The permission level for this access policy. Note that a project ADMINISTRATOR is also known as
            a project owner.
        client_token(Text, optional): A unique case-sensitive identifier that you can provide to ensure the idempotency of the
            request. Don't reuse this client token if a new idempotent request is required. Defaults to None.
        tags(Dict, optional): A list of key-value pairs that contain metadata for the access policy. For more information, see
            Tagging your IoT SiteWise resources in the IoT SiteWise User Guide. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iotsitewise.access_policy.present:
                - name: value
                - access_policy_identity: value
                - access_policy_resource: value
                - access_policy_permission: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iotsitewise.access_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.iotsitewise.describe_access_policy(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iotsitewise.create_access_policy(
                ctx,
                
                
                **{"accessPolicyIdentity": access_policy_identity, "accessPolicyResource": access_policy_resource, "accessPolicyPermission": access_policy_permission, "clientToken": client_token, "tags": tags}
            )
            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.iotsitewise.describe_access_policy(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, access_policy_id: Text, client_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an access policy that grants the specified identity access to the specified IoT SiteWise Monitor
    resource. You can use this operation to revoke access to an IoT SiteWise Monitor resource.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        access_policy_id(Text): The ID of the access policy to be deleted.
        client_token(Text, optional): A unique case-sensitive identifier that you can provide to ensure the idempotency of the
            request. Don't reuse this client token if a new idempotent request is required. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

