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

hub.exec.boto3.client.emr.create_studio
hub.exec.boto3.client.emr.delete_studio
hub.exec.boto3.client.emr.describe_studio
hub.exec.boto3.client.emr.update_studio
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, auth_mode: Text, vpc_id: Text, subnet_ids: List, service_role: Text, user_role: Text, workspace_security_group_id: Text, engine_security_group_id: Text, default_s3_location: Text, description: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new Amazon EMR Studio.

    Args:
        name(Text): A descriptive name for the Amazon EMR Studio.
        description(Text, optional): A detailed description of the Amazon EMR Studio. Defaults to None.
        auth_mode(Text): Specifies whether the Studio authenticates users using single sign-on (SSO) or IAM. Amazon EMR
            Studio currently only supports SSO authentication.
        vpc_id(Text): The ID of the Amazon Virtual Private Cloud (Amazon VPC) to associate with the Studio.
        subnet_ids(List): A list of subnet IDs to associate with the Amazon EMR Studio. A Studio can have a maximum of 5
            subnets. The subnets must belong to the VPC specified by VpcId. Studio users can create a
            Workspace in any of the specified subnets.
        service_role(Text): The IAM role that will be assumed by the Amazon EMR Studio. The service role provides a way for
            Amazon EMR Studio to interoperate with other Amazon Web Services services.
        user_role(Text): The IAM user role that will be assumed by users and groups logged in to an Amazon EMR Studio.
            The permissions attached to this IAM role can be scoped down for each user or group using
            session policies.
        workspace_security_group_id(Text): The ID of the Amazon EMR Studio Workspace security group. The Workspace security group allows
            outbound network traffic to resources in the Engine security group, and it must be in the same
            VPC specified by VpcId.
        engine_security_group_id(Text): The ID of the Amazon EMR Studio Engine security group. The Engine security group allows inbound
            network traffic from the Workspace security group, and it must be in the same VPC specified by
            VpcId.
        default_s3_location(Text): The Amazon S3 location to back up Amazon EMR Studio Workspaces and notebook files.
        tags(List, optional): A list of tags to associate with the Amazon EMR Studio. Tags are user-defined key-value pairs
            that consist of a required key string with a maximum of 128 characters, and an optional value
            string with a maximum of 256 characters. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.emr.studio.present:
                - name: value
                - auth_mode: value
                - vpc_id: value
                - subnet_ids: value
                - service_role: value
                - user_role: value
                - workspace_security_group_id: value
                - engine_security_group_id: value
                - default_s3_location: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.emr.studio.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.emr.describe_studio(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.emr.create_studio(
                ctx,
                
                
                **{"Name": name, "Description": description, "AuthMode": auth_mode, "VpcId": vpc_id, "SubnetIds": subnet_ids, "ServiceRole": service_role, "UserRole": user_role, "WorkspaceSecurityGroupId": workspace_security_group_id, "EngineSecurityGroupId": engine_security_group_id, "DefaultS3Location": default_s3_location, "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.emr.describe_studio(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, studio_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes an Amazon EMR Studio from the Studio metadata store.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        studio_id(Text): The ID of the Amazon EMR Studio.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

