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

hub.exec.boto3.client.sagemaker.create_domain
hub.exec.boto3.client.sagemaker.delete_domain
hub.exec.boto3.client.sagemaker.describe_domain
hub.exec.boto3.client.sagemaker.list_domains
hub.exec.boto3.client.sagemaker.update_domain
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, domain_name: Text, auth_mode: Text, default_user_settings: Dict, subnet_ids: List, vpc_id: Text, tags: List = None, app_network_access_type: Text = None, home_efs_file_system_kms_key_id: Text = None, kms_key_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a Domain used by Amazon SageMaker Studio. A domain consists of an associated Amazon Elastic File System
    (EFS) volume, a list of authorized users, and a variety of security, application, policy, and Amazon Virtual
    Private Cloud (VPC) configurations. An Amazon Web Services account is limited to one domain per region. Users
    within a domain can share notebook files and other artifacts with each other.  EFS storage  When a domain is
    created, an EFS volume is created for use by all of the users within the domain. Each user receives a private
    home directory within the EFS volume for notebooks, Git repositories, and data files. SageMaker uses the Amazon
    Web Services Key Management Service (Amazon Web Services KMS) to encrypt the EFS volume attached to the domain
    with an Amazon Web Services managed customer master key (CMK) by default. For more control, you can specify a
    customer managed CMK. For more information, see Protect Data at Rest Using Encryption.  VPC configuration  All
    SageMaker Studio traffic between the domain and the EFS volume is through the specified VPC and subnets. For
    other Studio traffic, you can specify the AppNetworkAccessType parameter. AppNetworkAccessType corresponds to
    the network access type that you choose when you onboard to Studio. The following options are available:
    PublicInternetOnly - Non-EFS traffic goes through a VPC managed by Amazon SageMaker, which allows internet
    access. This is the default value.    VpcOnly - All Studio traffic is through the specified VPC and subnets.
    Internet access is disabled by default. To allow internet access, you must specify a NAT gateway. When internet
    access is disabled, you won't be able to run a Studio notebook or to train or host models unless your VPC has an
    interface endpoint to the SageMaker API and runtime or a NAT gateway and your security groups allow outbound
    connections.    NFS traffic over TCP on port 2049 needs to be allowed in both inbound and outbound rules in
    order to launch a SageMaker Studio app successfully.  For more information, see Connect SageMaker Studio
    Notebooks to Resources in a VPC.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain_name(Text): A name for the domain.
        auth_mode(Text): The mode of authentication that members use to access the domain.
        default_user_settings(Dict): The default settings to use to create a user profile when UserSettings isn't specified in the
            call to the CreateUserProfile API.  SecurityGroups is aggregated when specified in both calls.
            For all other settings in UserSettings, the values specified in CreateUserProfile take
            precedence over those specified in CreateDomain.
        subnet_ids(List): The VPC subnets that Studio uses for communication.
        vpc_id(Text): The ID of the Amazon Virtual Private Cloud (VPC) that Studio uses for communication.
        tags(List, optional): Tags to associated with the Domain. Each tag consists of a key and an optional value. Tag keys
            must be unique per resource. Tags are searchable using the Search API. Tags that you specify for
            the Domain are also added to all Apps that the Domain launches. Defaults to None.
        app_network_access_type(Text, optional): Specifies the VPC used for non-EFS traffic. The default value is PublicInternetOnly.
            PublicInternetOnly - Non-EFS traffic is through a VPC managed by Amazon SageMaker, which allows
            direct internet access    VpcOnly - All Studio traffic is through the specified VPC and subnets. Defaults to None.
        home_efs_file_system_kms_key_id(Text, optional): This member is deprecated and replaced with KmsKeyId. Defaults to None.
        kms_key_id(Text, optional): SageMaker uses Amazon Web Services KMS to encrypt the EFS volume attached to the domain with an
            Amazon Web Services managed customer master key (CMK) by default. For more control, specify a
            customer managed CMK. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.sagemaker.domain.present:
                - name: value
                - domain_name: value
                - auth_mode: value
                - default_user_settings: value
                - subnet_ids: value
                - vpc_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.sagemaker.domain.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_domain(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sagemaker.create_domain(
                ctx,
                
                
                **{"DomainName": domain_name, "AuthMode": auth_mode, "DefaultUserSettings": default_user_settings, "SubnetIds": subnet_ids, "VpcId": vpc_id, "Tags": tags, "AppNetworkAccessType": app_network_access_type, "HomeEfsFileSystemKmsKeyId": home_efs_file_system_kms_key_id, "KmsKeyId": kms_key_id}
            )
            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_domain(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, domain_id: Text, retention_policy: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Used to delete a domain. If you onboarded with IAM mode, you will need to delete your domain to onboard again
    using SSO. Use with caution. All of the members of the domain will lose access to their EFS volume, including
    data, notebooks, and other artifacts.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain_id(Text): The domain ID.
        retention_policy(Dict, optional): The retention policy for this domain, which specifies whether resources will be retained after
            the Domain is deleted. By default, all resources are retained (not automatically deleted). Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

