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

hub.exec.boto3.client.sagemaker.create_notebook_instance_lifecycle_config
hub.exec.boto3.client.sagemaker.delete_notebook_instance_lifecycle_config
hub.exec.boto3.client.sagemaker.describe_notebook_instance_lifecycle_config
hub.exec.boto3.client.sagemaker.list_notebook_instance_lifecycle_configs
hub.exec.boto3.client.sagemaker.update_notebook_instance_lifecycle_config
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, notebook_instance_lifecycle_config_name: Text, on_create: List = None, on_start: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a lifecycle configuration that you can associate with a notebook instance. A lifecycle configuration is
    a collection of shell scripts that run when you create or start a notebook instance. Each lifecycle
    configuration script has a limit of 16384 characters. The value of the $PATH environment variable that is
    available to both scripts is /sbin:bin:/usr/sbin:/usr/bin. View CloudWatch Logs for notebook instance lifecycle
    configurations in log group /aws/sagemaker/NotebookInstances in log stream [notebook-instance-
    name]/[LifecycleConfigHook]. Lifecycle configuration scripts cannot run for longer than 5 minutes. If a script
    runs for longer than 5 minutes, it fails and the notebook instance is not created or started. For information
    about notebook instance lifestyle configurations, see Step 2.1: (Optional) Customize a Notebook Instance.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        notebook_instance_lifecycle_config_name(Text): The name of the lifecycle configuration.
        on_create(List, optional): A shell script that runs only once, when you create a notebook instance. The shell script must
            be a base64-encoded string. Defaults to None.
        on_start(List, optional): A shell script that runs every time you start a notebook instance, including when you create the
            notebook instance. The shell script must be a base64-encoded string. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sagemaker.create_notebook_instance_lifecycle_config(
                ctx,
                
                
                **{"NotebookInstanceLifecycleConfigName": notebook_instance_lifecycle_config_name, "OnCreate": on_create, "OnStart": on_start}
            )
            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_lifecycle_config(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, notebook_instance_lifecycle_config_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a notebook instance lifecycle configuration.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        notebook_instance_lifecycle_config_name(Text): The name of the lifecycle configuration to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

