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

hub.exec.boto3.client.sso_admin.create_permission_set
hub.exec.boto3.client.sso_admin.delete_permission_set
hub.exec.boto3.client.sso_admin.describe_permission_set
hub.exec.boto3.client.sso_admin.list_permission_sets
hub.exec.boto3.client.sso_admin.provision_permission_set
hub.exec.boto3.client.sso_admin.update_permission_set
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, instance_arn: Text, description: Text = None, session_duration: Text = None, relay_state: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a permission set within a specified SSO instance.  To grant users and groups access to Amazon Web
    Services account resources, use  CreateAccountAssignment .

    Args:
        name(Text): The name of the PermissionSet.
        description(Text, optional): The description of the PermissionSet. Defaults to None.
        instance_arn(Text): The ARN of the SSO instance under which the operation will be executed. For more information
            about ARNs, see Amazon Resource Names (ARNs) and Amazon Web Services Service Namespaces in the
            Amazon Web Services General Reference.
        session_duration(Text, optional): The length of time that the application user sessions are valid in the ISO-8601 standard. Defaults to None.
        relay_state(Text, optional): Used to redirect users within the application during the federation authentication process. Defaults to None.
        tags(List, optional): The tags to attach to the new PermissionSet. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sso_admin.create_permission_set(
                ctx,
                
                
                **{"Name": name, "Description": description, "InstanceArn": instance_arn, "SessionDuration": session_duration, "RelayState": relay_state, "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.sso_admin.describe_permission_set(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, instance_arn: Text, permission_set_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified permission set.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        instance_arn(Text): The ARN of the SSO instance under which the operation will be executed. For more information
            about ARNs, see Amazon Resource Names (ARNs) and Amazon Web Services Service Namespaces in the
            Amazon Web Services General Reference.
        permission_set_arn(Text): The ARN of the permission set that should be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.sso_admin.permission_set.absent:
                - name: value
                - instance_arn: value
                - permission_set_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.sso_admin.permission_set.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.sso_admin.describe_permission_set(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.sso_admin.delete_permission_set(
                ctx,
                
                
                **{"InstanceArn": instance_arn, "PermissionSetArn": permission_set_arn}
            )
            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.sso_admin.describe_permission_set(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

