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

hub.exec.boto3.client.sagemaker.create_endpoint
hub.exec.boto3.client.sagemaker.delete_endpoint
hub.exec.boto3.client.sagemaker.describe_endpoint
hub.exec.boto3.client.sagemaker.list_endpoints
hub.exec.boto3.client.sagemaker.update_endpoint
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, endpoint_name: Text, endpoint_config_name: Text, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an endpoint using the endpoint configuration specified in the request. Amazon SageMaker uses the
    endpoint to provision resources and deploy models. You create the endpoint configuration with the
    CreateEndpointConfig API.   Use this API to deploy models using Amazon SageMaker hosting services.  For an
    example that calls this method when deploying a model to Amazon SageMaker hosting services, see the Create
    Endpoint example notebook.    You must not delete an EndpointConfig that is in use by an endpoint that is live
    or while the UpdateEndpoint or CreateEndpoint operations are being performed on the endpoint. To update an
    endpoint, you must create a new EndpointConfig.  The endpoint name must be unique within an Amazon Web Services
    Region in your Amazon Web Services account.  When it receives the request, Amazon SageMaker creates the
    endpoint, launches the resources (ML compute instances), and deploys the model(s) on them.   When you call
    CreateEndpoint, a load call is made to DynamoDB to verify that your endpoint configuration exists. When you read
    data from a DynamoDB table supporting  Eventually Consistent Reads , the response might not reflect the results
    of a recently completed write operation. The response might include some stale data. If the dependent entities
    are not yet in DynamoDB, this causes a validation error. If you repeat your read request after a short time, the
    response should return the latest data. So retry logic is recommended to handle these possible issues. We also
    recommend that customers call DescribeEndpointConfig before calling CreateEndpoint to minimize the potential
    impact of a DynamoDB eventually consistent read.  When Amazon SageMaker receives the request, it sets the
    endpoint status to Creating. After it creates the endpoint, it sets the status to InService. Amazon SageMaker
    can then process incoming requests for inferences. To check the status of an endpoint, use the DescribeEndpoint
    API. If any of the models hosted at this endpoint get model data from an Amazon S3 location, Amazon SageMaker
    uses Amazon Web Services Security Token Service to download model artifacts from the S3 path you provided.
    Amazon Web Services STS is activated in your IAM user account by default. If you previously deactivated Amazon
    Web Services STS for a region, you need to reactivate Amazon Web Services STS for that region. For more
    information, see Activating and Deactivating Amazon Web Services STS in an Amazon Web Services Region in the
    Amazon Web Services Identity and Access Management User Guide.   To add the IAM role policies for using this API
    operation, go to the IAM console, and choose Roles in the left navigation pane. Search the IAM role that you
    want to grant access to use the CreateEndpoint and CreateEndpointConfig API operations, add the following
    policies to the role.    Option 1: For a full Amazon SageMaker access, search and attach the
    AmazonSageMakerFullAccess policy.   Option 2: For granting a limited access to an IAM role, paste the following
    Action elements manually into the JSON file of the IAM role:   "Action": ["sagemaker:CreateEndpoint",
    "sagemaker:CreateEndpointConfig"]   "Resource": [   "arn:aws:sagemaker:region:account-id:endpoint/endpointName"
    "arn:aws:sagemaker:region:account-id:endpoint-config/endpointConfigName"   ]  For more information, see Amazon
    SageMaker API Permissions: Actions, Permissions, and Resources Reference.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        endpoint_name(Text): The name of the endpoint.The name must be unique within an Amazon Web Services Region in your
            Amazon Web Services account. The name is case-insensitive in CreateEndpoint, but the case is
            preserved and must be matched in .
        endpoint_config_name(Text): The name of an endpoint configuration. For more information, see CreateEndpointConfig.
        tags(List, optional): An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources
            in different ways, for example, by purpose, owner, or environment. For more information, see
            Tagging Amazon Web Services Resources. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sagemaker.create_endpoint(
                ctx,
                
                
                **{"EndpointName": endpoint_name, "EndpointConfigName": endpoint_config_name, "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_endpoint(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, endpoint_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an endpoint. Amazon SageMaker frees up all of the resources that were deployed when the endpoint was
    created.  Amazon SageMaker retires any custom KMS key grants associated with the endpoint, meaning you don't
    need to use the RevokeGrant API call.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        endpoint_name(Text): The name of the endpoint that you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

