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

hub.exec.boto3.client.apigateway.create_stage
hub.exec.boto3.client.apigateway.delete_stage
hub.exec.boto3.client.apigateway.get_stages
hub.exec.boto3.client.apigateway.update_stage
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, rest_api_id: Text, stage_name: Text, deployment_id: Text, description: Text = None, cache_cluster_enabled: bool = None, cache_cluster_size: Text = None, variables: Dict = None, documentation_version: Text = None, canary_settings: Dict = None, tracing_enabled: bool = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new Stage resource that references a pre-existing Deployment for the API.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        rest_api_id(Text): [Required] The string identifier of the associated RestApi.
        stage_name(Text): [Required] The name for the Stage resource. Stage names can only contain alphanumeric
            characters, hyphens, and underscores. Maximum length is 128 characters.
        deployment_id(Text): [Required] The identifier of the Deployment resource for the Stage resource.
        description(Text, optional): The description of the Stage resource. Defaults to None.
        cache_cluster_enabled(bool, optional): Whether cache clustering is enabled for the stage. Defaults to None.
        cache_cluster_size(Text, optional): The stage's cache cluster size. Defaults to None.
        variables(Dict, optional): A map that defines the stage variables for the new Stage resource. Variable names can have
            alphanumeric and underscore characters, and the values must match [A-Za-z0-9-._~:/?#&=,]+. Defaults to None.
        documentation_version(Text, optional): The version of the associated API documentation. Defaults to None.
        canary_settings(Dict, optional): The canary deployment settings of this stage. Defaults to None.
        tracing_enabled(bool, optional): Specifies whether active tracing with X-ray is enabled for the Stage. Defaults to None.
        tags(Dict, optional): The key-value map of strings. The valid character set is [a-zA-Z+-=._:/]. The tag key can be up
            to 128 characters and must not start with aws:. The tag value can be up to 256 characters. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.apigateway.stage.present:
                - name: value
                - rest_api_id: value
                - stage_name: value
                - deployment_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.apigateway.stage.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.apigateway.get_stages(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.apigateway.create_stage(
                ctx,
                
                
                **{"restApiId": rest_api_id, "stageName": stage_name, "deploymentId": deployment_id, "description": description, "cacheClusterEnabled": cache_cluster_enabled, "cacheClusterSize": cache_cluster_size, "variables": variables, "documentationVersion": documentation_version, "canarySettings": canary_settings, "tracingEnabled": tracing_enabled, "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.apigateway.get_stages(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, rest_api_id: Text, stage_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a Stage resource.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        rest_api_id(Text): [Required] The string identifier of the associated RestApi.
        stage_name(Text): [Required] The name of the Stage resource to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.apigateway.stage.absent:
                - name: value
                - rest_api_id: value
                - stage_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.apigateway.stage.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.apigateway.get_stages(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.apigateway.delete_stage(
                ctx,
                
                
                **{"restApiId": rest_api_id, "stageName": stage_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.apigateway.get_stages(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

