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

hub.exec.boto3.client.sagemaker.create_app
hub.exec.boto3.client.sagemaker.delete_app
hub.exec.boto3.client.sagemaker.describe_app
hub.exec.boto3.client.sagemaker.list_apps
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, domain_id: Text, user_profile_name: Text, app_type: Text, app_name: Text, tags: List = None, resource_spec: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a running app for the specified UserProfile. Supported apps are JupyterServer and KernelGateway. This
    operation is automatically invoked by Amazon SageMaker Studio upon access to the associated Domain, and when new
    kernel configurations are selected by the user. A user may have multiple Apps active simultaneously.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain_id(Text): The domain ID.
        user_profile_name(Text): The user profile name.
        app_type(Text): The type of app. Supported apps are JupyterServer and KernelGateway. TensorBoard is not
            supported.
        app_name(Text): The name of the app.
        tags(List, optional): Each tag consists of a key and an optional value. Tag keys must be unique per resource. Defaults to None.
        resource_spec(Dict, optional): The instance type and the Amazon Resource Name (ARN) of the SageMaker image created on the
            instance. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.sagemaker.app.present:
                - name: value
                - domain_id: value
                - user_profile_name: value
                - app_type: value
                - app_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.sagemaker.app.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_app(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sagemaker.create_app(
                ctx,
                
                
                **{"DomainId": domain_id, "UserProfileName": user_profile_name, "AppType": app_type, "AppName": app_name, "Tags": tags, "ResourceSpec": resource_spec}
            )
            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_app(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, domain_id: Text, user_profile_name: Text, app_type: Text, app_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Used to stop and delete an app.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain_id(Text): The domain ID.
        user_profile_name(Text): The user profile name.
        app_type(Text): The type of app.
        app_name(Text): The name of the app.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.sagemaker.delete_app(
                ctx,
                
                
                **{"DomainId": domain_id, "UserProfileName": user_profile_name, "AppType": app_type, "AppName": app_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_app(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

