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

hub.exec.boto3.client.sagemaker.create_pipeline
hub.exec.boto3.client.sagemaker.delete_pipeline
hub.exec.boto3.client.sagemaker.describe_pipeline
hub.exec.boto3.client.sagemaker.list_pipelines
hub.exec.boto3.client.sagemaker.update_pipeline
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, pipeline_name: Text, pipeline_definition: Text, client_request_token: Text, role_arn: Text, pipeline_display_name: Text = None, pipeline_description: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a pipeline using a JSON pipeline definition.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        pipeline_name(Text): The name of the pipeline.
        pipeline_display_name(Text, optional): The display name of the pipeline. Defaults to None.
        pipeline_definition(Text): The JSON pipeline definition of the pipeline.
        pipeline_description(Text, optional): A description of the pipeline. Defaults to None.
        client_request_token(Text): A unique, case-sensitive identifier that you provide to ensure the idempotency of the operation.
            An idempotent operation completes no more than one time.
        role_arn(Text): The Amazon Resource Name (ARN) of the role used by the pipeline to access and create resources.
        tags(List, optional): A list of tags to apply to the created pipeline. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.sagemaker.pipeline.present:
                - name: value
                - pipeline_name: value
                - pipeline_definition: value
                - client_request_token: value
                - role_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.sagemaker.pipeline.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_pipeline(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sagemaker.create_pipeline(
                ctx,
                
                
                **{"PipelineName": pipeline_name, "PipelineDisplayName": pipeline_display_name, "PipelineDefinition": pipeline_definition, "PipelineDescription": pipeline_description, "ClientRequestToken": client_request_token, "RoleArn": role_arn, "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.sagemaker.describe_pipeline(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, pipeline_name: Text, client_request_token: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a pipeline if there are no running instances of the pipeline. To delete a pipeline, you must stop all
    running instances of the pipeline using the StopPipelineExecution API. When you delete a pipeline, all instances
    of the pipeline are deleted.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        pipeline_name(Text): The name of the pipeline to delete.
        client_request_token(Text): A unique, case-sensitive identifier that you provide to ensure the idempotency of the operation.
            An idempotent operation completes no more than one time.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

