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

hub.exec.boto3.client.sagemaker.create_notebook_instance
hub.exec.boto3.client.sagemaker.delete_notebook_instance
hub.exec.boto3.client.sagemaker.describe_notebook_instance
hub.exec.boto3.client.sagemaker.list_notebook_instances
hub.exec.boto3.client.sagemaker.start_notebook_instance
hub.exec.boto3.client.sagemaker.stop_notebook_instance
hub.exec.boto3.client.sagemaker.update_notebook_instance
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, notebook_instance_name: Text, instance_type: Text, role_arn: Text, subnet_id: Text = None, security_group_ids: List = None, kms_key_id: Text = None, tags: List = None, lifecycle_config_name: Text = None, direct_internet_access: Text = None, volume_size_in_gb: int = None, accelerator_types: List = None, default_code_repository: Text = None, additional_code_repositories: List = None, root_access: Text = None, platform_identifier: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an Amazon SageMaker notebook instance. A notebook instance is a machine learning (ML) compute instance
    running on a Jupyter notebook.  In a CreateNotebookInstance request, specify the type of ML compute instance
    that you want to run. Amazon SageMaker launches the instance, installs common libraries that you can use to
    explore datasets for model training, and attaches an ML storage volume to the notebook instance.  Amazon
    SageMaker also provides a set of example notebooks. Each notebook demonstrates how to use Amazon SageMaker with
    a specific algorithm or with a machine learning framework.  After receiving the request, Amazon SageMaker does
    the following:   Creates a network interface in the Amazon SageMaker VPC.   (Option) If you specified SubnetId,
    Amazon SageMaker creates a network interface in your own VPC, which is inferred from the subnet ID that you
    provide in the input. When creating this network interface, Amazon SageMaker attaches the security group that
    you specified in the request to the network interface that it creates in your VPC.   Launches an EC2 instance of
    the type specified in the request in the Amazon SageMaker VPC. If you specified SubnetId of your VPC, Amazon
    SageMaker specifies both network interfaces when launching this instance. This enables inbound traffic from your
    own VPC to the notebook instance, assuming that the security groups allow it.   After creating the notebook
    instance, Amazon SageMaker returns its Amazon Resource Name (ARN). You can't change the name of a notebook
    instance after you create it. After Amazon SageMaker creates the notebook instance, you can connect to the
    Jupyter server and work in Jupyter notebooks. For example, you can write code to explore a dataset that you can
    use for model training, train a model, host models by creating Amazon SageMaker endpoints, and validate hosted
    models.  For more information, see How It Works.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        notebook_instance_name(Text): The name of the new notebook instance.
        instance_type(Text): The type of ML compute instance to launch for the notebook instance.
        subnet_id(Text, optional): The ID of the subnet in a VPC to which you would like to have a connectivity from your ML
            compute instance. Defaults to None.
        security_group_ids(List, optional): The VPC security group IDs, in the form sg-xxxxxxxx. The security groups must be for the same
            VPC as specified in the subnet. Defaults to None.
        role_arn(Text):  When you send any requests to Amazon Web Services resources from the notebook instance, Amazon
            SageMaker assumes this role to perform tasks on your behalf. You must grant this role necessary
            permissions so Amazon SageMaker can perform these tasks. The policy must allow the Amazon
            SageMaker service principal (sagemaker.amazonaws.com) permissions to assume this role. For more
            information, see Amazon SageMaker Roles.   To be able to pass this role to Amazon SageMaker, the
            caller of this API must have the iam:PassRole permission.
        kms_key_id(Text, optional): The Amazon Resource Name (ARN) of a Amazon Web Services Key Management Service key that Amazon
            SageMaker uses to encrypt data on the storage volume attached to your notebook instance. The KMS
            key you provide must be enabled. For information, see Enabling and Disabling Keys in the Amazon
            Web Services Key Management Service Developer Guide. Defaults to None.
        tags(List, optional): An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources
            in different ways, for example, by purpose, owner, or environment. For more information, see
            Tagging Amazon Web Services Resources. Defaults to None.
        lifecycle_config_name(Text, optional): The name of a lifecycle configuration to associate with the notebook instance. For information
            about lifestyle configurations, see Step 2.1: (Optional) Customize a Notebook Instance. Defaults to None.
        direct_internet_access(Text, optional): Sets whether Amazon SageMaker provides internet access to the notebook instance. If you set this
            to Disabled this notebook instance is able to access resources only in your VPC, and is not be
            able to connect to Amazon SageMaker training and endpoint services unless you configure a NAT
            Gateway in your VPC. For more information, see Notebook Instances Are Internet-Enabled by
            Default. You can set the value of this parameter to Disabled only if you set a value for the
            SubnetId parameter. Defaults to None.
        volume_size_in_gb(int, optional): The size, in GB, of the ML storage volume to attach to the notebook instance. The default value
            is 5 GB. Defaults to None.
        accelerator_types(List, optional): A list of Elastic Inference (EI) instance types to associate with this notebook instance.
            Currently, only one instance type can be associated with a notebook instance. For more
            information, see Using Elastic Inference in Amazon SageMaker. Defaults to None.
        default_code_repository(Text, optional): A Git repository to associate with the notebook instance as its default code repository. This
            can be either the name of a Git repository stored as a resource in your account, or the URL of a
            Git repository in Amazon Web Services CodeCommit or in any other Git repository. When you open a
            notebook instance, it opens in the directory that contains this repository. For more
            information, see Associating Git Repositories with Amazon SageMaker Notebook Instances. Defaults to None.
        additional_code_repositories(List, optional): An array of up to three Git repositories to associate with the notebook instance. These can be
            either the names of Git repositories stored as resources in your account, or the URL of Git
            repositories in Amazon Web Services CodeCommit or in any other Git repository. These
            repositories are cloned at the same level as the default repository of your notebook instance.
            For more information, see Associating Git Repositories with Amazon SageMaker Notebook Instances. Defaults to None.
        root_access(Text, optional): Whether root access is enabled or disabled for users of the notebook instance. The default value
            is Enabled.  Lifecycle configurations need root access to be able to set up a notebook instance.
            Because of this, lifecycle configurations associated with a notebook instance always run with
            root access even if you disable root access for users. Defaults to None.
        platform_identifier(Text, optional): The platform identifier of the notebook instance runtime environment. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.sagemaker.notebook_instance.present:
                - name: value
                - notebook_instance_name: value
                - instance_type: value
                - role_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.sagemaker.notebook_instance.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.sagemaker.describe_notebook_instance(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sagemaker.create_notebook_instance(
                ctx,
                
                
                **{"NotebookInstanceName": notebook_instance_name, "InstanceType": instance_type, "SubnetId": subnet_id, "SecurityGroupIds": security_group_ids, "RoleArn": role_arn, "KmsKeyId": kms_key_id, "Tags": tags, "LifecycleConfigName": lifecycle_config_name, "DirectInternetAccess": direct_internet_access, "VolumeSizeInGB": volume_size_in_gb, "AcceleratorTypes": accelerator_types, "DefaultCodeRepository": default_code_repository, "AdditionalCodeRepositories": additional_code_repositories, "RootAccess": root_access, "PlatformIdentifier": platform_identifier}
            )
            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.sagemaker.describe_notebook_instance(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, notebook_instance_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Deletes an Amazon SageMaker notebook instance. Before you can delete a notebook instance, you must call the
    StopNotebookInstance API.   When you delete a notebook instance, you lose all of your data. Amazon SageMaker
    removes the ML compute instance, and deletes the ML storage volume and the network interface associated with the
    notebook instance.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        notebook_instance_name(Text): The name of the Amazon SageMaker notebook instance to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

