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

hub.exec.boto3.client.lookoutvision.create_model
hub.exec.boto3.client.lookoutvision.delete_model
hub.exec.boto3.client.lookoutvision.describe_model
hub.exec.boto3.client.lookoutvision.list_models
hub.exec.boto3.client.lookoutvision.start_model
hub.exec.boto3.client.lookoutvision.stop_model
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, project_name: Text, output_config: Dict, description: Text = None, kms_key_id: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new version of a model within an an Amazon Lookout for Vision project. CreateModel is an asynchronous
    operation in which Amazon Lookout for Vision trains, tests, and evaluates a new version of a model.  To get the
    current status, check the Status field returned in the response from DescribeModel. If the project has a single
    dataset, Amazon Lookout for Vision internally splits the dataset to create a training and a test dataset. If the
    project has a training and a test dataset, Lookout for Vision uses the respective datasets to train and test the
    model.  After training completes, the evaluation metrics are stored at the location specified in OutputConfig.
    This operation requires permissions to perform the lookoutvision:CreateModel operation. If you want to tag your
    model, you also require permission to the lookoutvision:TagResource operation.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        project_name(Text): The name of the project in which you want to create a model version.
        description(Text, optional): A description for the version of the model. Defaults to None.
        output_config(Dict): The location where Amazon Lookout for Vision saves the training results.
        kms_key_id(Text, optional): The identifier for your AWS Key Management Service (AWS KMS) customer master key (CMK). The key
            is used to encrypt training and test images copied into the service for model training. Your
            source images are unaffected. If this parameter is not specified, the copied images are
            encrypted by a key that AWS owns and manages. Defaults to None.
        tags(List, optional): A set of tags (key-value pairs) that you want to attach to the model. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.lookoutvision.model.present:
                - name: value
                - project_name: value
                - output_config: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.lookoutvision.model.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.lookoutvision.describe_model(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lookoutvision.create_model(
                ctx,
                
                ClientToken=name,
                **{"ProjectName": project_name, "Description": description, "OutputConfig": output_config, "KmsKeyId": kms_key_id, "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.lookoutvision.describe_model(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, project_name: Text, model_version: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an Amazon Lookout for Vision model. You can't delete a running model. To stop a running model, use the
    StopModel operation. It might take a few seconds to delete a model. To determine if a model has been deleted,
    call ListProjects and check if the version of the model (ModelVersion) is in the Models array.  This operation
    requires permissions to perform the lookoutvision:DeleteModel operation.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        project_name(Text): The name of the project that contains the model that you want to delete.
        model_version(Text): The version of the model that you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.lookoutvision.model.absent:
                - name: value
                - project_name: value
                - model_version: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.lookoutvision.model.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.lookoutvision.describe_model(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.lookoutvision.delete_model(
                ctx,
                
                ClientToken=name,
                **{"ProjectName": project_name, "ModelVersion": model_version}
            )
            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.lookoutvision.describe_model(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

