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

hub.exec.boto3.client.finspace.create_environment
hub.exec.boto3.client.finspace.delete_environment
hub.exec.boto3.client.finspace.get_environment
hub.exec.boto3.client.finspace.list_environments
hub.exec.boto3.client.finspace.update_environment
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, description: Text = None, kms_key_id: Text = None, tags: Dict = None, federation_mode: Text = None, federation_parameters: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create a new FinSpace environment.

    Args:
        name(Text): The name of the FinSpace environment to be created.
        description(Text, optional): The description of the FinSpace environment to be created. Defaults to None.
        kms_key_id(Text, optional): The KMS key id to encrypt your data in the FinSpace environment. Defaults to None.
        tags(Dict, optional): Add tags to your FinSpace environment. Defaults to None.
        federation_mode(Text, optional): Authentication mode for the environment.    FEDERATED - Users access FinSpace through Single
            Sign On (SSO) via your Identity provider.    LOCAL - Users access FinSpace via email and
            password managed within the FinSpace environment. Defaults to None.
        federation_parameters(Dict, optional): Configuration information when authentication mode is FEDERATED. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.finspace.create_environment(
                ctx,
                
                
                **{"Name": name, "description": description, "kmsKeyId": kms_key_id, "tags": tags, "federationMode": federation_mode, "federationParameters": federation_parameters}
            )
            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.finspace.get_environment(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, environment_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Delete an FinSpace environment.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        environment_id(Text): The identifier for the FinSpace environment.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.finspace.environment.absent:
                - name: value
                - environment_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.finspace.environment.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.finspace.get_environment(name)

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

