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

hub.exec.boto3.client.rekognition.create_project_version
hub.exec.boto3.client.rekognition.delete_project_version
hub.exec.boto3.client.rekognition.describe_project_versions
hub.exec.boto3.client.rekognition.start_project_version
hub.exec.boto3.client.rekognition.stop_project_version
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, project_arn: Text, version_name: Text, output_config: Dict, training_data: Dict, testing_data: Dict, tags: Dict = None, kms_key_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new version of a model and begins training. Models are managed as part of an Amazon Rekognition Custom
    Labels project. You can specify one training dataset and one testing dataset. The response from
    CreateProjectVersion is an Amazon Resource Name (ARN) for the version of the model.  Training takes a while to
    complete. You can get the current status by calling DescribeProjectVersions. Once training has successfully
    completed, call DescribeProjectVersions to get the training results and evaluate the model.  After evaluating
    the model, you start the model by calling StartProjectVersion. This operation requires permissions to perform
    the rekognition:CreateProjectVersion action.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        project_arn(Text): The ARN of the Amazon Rekognition Custom Labels project that manages the model that you want to
            train.
        version_name(Text): A name for the version of the model. This value must be unique.
        output_config(Dict): The Amazon S3 bucket location to store the results of training. The S3 bucket can be in any AWS
            account as long as the caller has s3:PutObject permissions on the S3 bucket.
        training_data(Dict): The dataset to use for training.
        testing_data(Dict): The dataset to use for testing.
        tags(Dict, optional):  A set of tags (key-value pairs) that you want to attach to the model. Defaults to None.
        kms_key_id(Text, optional): The identifier for your AWS Key Management Service (AWS KMS) customer master key (CMK). You can
            supply the Amazon Resource Name (ARN) of your CMK, the ID of your CMK, an alias for your CMK, or
            an alias ARN. The key is used to encrypt training and test images copied into the service for
            model training. Your source images are unaffected. The key is also used to encrypt training
            results and manifest files written to the output Amazon S3 bucket (OutputConfig). If you choose
            to use your own CMK, you need the following permissions on the CMK.   kms:CreateGrant
            kms:DescribeKey   kms:GenerateDataKey   kms:Decrypt   If you don't specify a value for KmsKeyId,
            images copied into the service are encrypted using a key that AWS owns and manages. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.rekognition.project_version.present:
                - name: value
                - project_arn: value
                - version_name: value
                - output_config: value
                - training_data: value
                - testing_data: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.rekognition.project_version.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.rekognition.describe_project_versions(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.rekognition.create_project_version(
                ctx,
                
                
                **{"ProjectArn": project_arn, "VersionName": version_name, "OutputConfig": output_config, "TrainingData": training_data, "TestingData": testing_data, "Tags": tags, "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.rekognition.describe_project_versions(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, project_version_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an Amazon Rekognition Custom Labels model.  You can't delete a model if it is running or if it is
    training. To check the status of a model, use the Status field returned from DescribeProjectVersions. To stop a
    running model call StopProjectVersion. If the model is training, wait until it finishes. This operation requires
    permissions to perform the rekognition:DeleteProjectVersion action.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        project_version_arn(Text): The Amazon Resource Name (ARN) of the model version that you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

