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

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



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, api_id: Text, stage_name: Text, access_log_settings: Dict = None, auto_deploy: bool = None, client_certificate_id: Text = None, default_route_settings: Dict = None, deployment_id: Text = None, description: Text = None, route_settings: Dict = None, stage_variables: Dict = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a Stage for an API.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        access_log_settings(Dict, optional): Settings for logging access in this stage. Defaults to None.
        api_id(Text): The API identifier.
        auto_deploy(bool, optional): Specifies whether updates to an API automatically trigger a new deployment. The default value is
            false. Defaults to None.
        client_certificate_id(Text, optional): The identifier of a client certificate for a Stage. Supported only for WebSocket APIs. Defaults to None.
        default_route_settings(Dict, optional): The default route settings for the stage. Defaults to None.
        deployment_id(Text, optional): The deployment identifier of the API stage. Defaults to None.
        description(Text, optional): The description for the API stage. Defaults to None.
        route_settings(Dict, optional): Route settings for the stage, by routeKey. Defaults to None.
        stage_name(Text): The name of the stage.
        stage_variables(Dict, optional): A map that defines the stage variables for a Stage. Variable names can have alphanumeric and
            underscore characters, and the values must match [A-Za-z0-9-._~:/?#&=,]+. Defaults to None.
        tags(Dict, optional): The collection of tags. Each tag element is associated with a given resource. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.apigatewayv2.create_stage(
                ctx,
                
                
                **{"AccessLogSettings": access_log_settings, "ApiId": api_id, "AutoDeploy": auto_deploy, "ClientCertificateId": client_certificate_id, "DefaultRouteSettings": default_route_settings, "DeploymentId": deployment_id, "Description": description, "RouteSettings": route_settings, "StageName": stage_name, "StageVariables": stage_variables, "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.apigatewayv2.get_stages(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        api_id(Text): The API identifier.
        stage_name(Text): The stage name. Stage names can only contain alphanumeric characters, hyphens, and underscores.
            Maximum length is 128 characters.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

