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

hub.exec.boto3.client.apigatewayv2.create_route
hub.exec.boto3.client.apigatewayv2.delete_route
hub.exec.boto3.client.apigatewayv2.get_routes
hub.exec.boto3.client.apigatewayv2.update_route
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, api_id: Text, route_key: Text, api_key_required: bool = None, authorization_scopes: List = None, authorization_type: Text = None, authorizer_id: Text = None, model_selection_expression: Text = None, operation_name: Text = None, request_models: Dict = None, request_parameters: Dict = None, route_response_selection_expression: Text = None, target: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a Route for an API.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        api_id(Text): The API identifier.
        api_key_required(bool, optional): Specifies whether an API key is required for the route. Supported only for WebSocket APIs. Defaults to None.
        authorization_scopes(List, optional): The authorization scopes supported by this route. Defaults to None.
        authorization_type(Text, optional): The authorization type for the route. For WebSocket APIs, valid values are NONE for open access,
            AWS_IAM for using AWS IAM permissions, and CUSTOM for using a Lambda authorizer For HTTP APIs,
            valid values are NONE for open access, JWT for using JSON Web Tokens, AWS_IAM for using AWS IAM
            permissions, and CUSTOM for using a Lambda authorizer. Defaults to None.
        authorizer_id(Text, optional): The identifier of the Authorizer resource to be associated with this route. The authorizer
            identifier is generated by API Gateway when you created the authorizer. Defaults to None.
        model_selection_expression(Text, optional): The model selection expression for the route. Supported only for WebSocket APIs. Defaults to None.
        operation_name(Text, optional): The operation name for the route. Defaults to None.
        request_models(Dict, optional): The request models for the route. Supported only for WebSocket APIs. Defaults to None.
        request_parameters(Dict, optional): The request parameters for the route. Supported only for WebSocket APIs. Defaults to None.
        route_key(Text): The route key for the route.
        route_response_selection_expression(Text, optional): The route response selection expression for the route. Supported only for WebSocket APIs. Defaults to None.
        target(Text, optional): The target for the route. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.apigatewayv2.create_route(
                ctx,
                
                
                **{"ApiId": api_id, "ApiKeyRequired": api_key_required, "AuthorizationScopes": authorization_scopes, "AuthorizationType": authorization_type, "AuthorizerId": authorizer_id, "ModelSelectionExpression": model_selection_expression, "OperationName": operation_name, "RequestModels": request_models, "RequestParameters": request_parameters, "RouteKey": route_key, "RouteResponseSelectionExpression": route_response_selection_expression, "Target": target}
            )
            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_routes(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        api_id(Text): The API identifier.
        route_id(Text): The route ID.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

