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

hub.exec.boto3.client.apigateway.delete_method
hub.exec.boto3.client.apigateway.get_method
hub.exec.boto3.client.apigateway.put_method
hub.exec.boto3.client.apigateway.update_method
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, rest_api_id: Text, resource_id: Text, http_method: Text, authorization_type: Text, authorizer_id: Text = None, api_key_required: bool = None, operation_name: Text = None, request_parameters: Dict = None, request_models: Dict = None, request_validator_id: Text = None, authorization_scopes: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Add a method to an existing Resource 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.
        resource_id(Text): [Required] The Resource identifier for the new Method resource.
        http_method(Text): [Required] Specifies the method request's HTTP method type.
        authorization_type(Text): [Required] The method's authorization type. Valid values are NONE for open access, AWS_IAM for
            using AWS IAM permissions, CUSTOM for using a custom authorizer, or COGNITO_USER_POOLS for using
            a Cognito user pool.
        authorizer_id(Text, optional): Specifies the identifier of an Authorizer to use on this Method, if the type is CUSTOM or
            COGNITO_USER_POOLS. The authorizer identifier is generated by API Gateway when you created the
            authorizer. Defaults to None.
        api_key_required(bool, optional): Specifies whether the method required a valid ApiKey. Defaults to None.
        operation_name(Text, optional): A human-friendly operation identifier for the method. For example, you can assign the
            operationName of ListPets for the GET /pets method in the PetStore example. Defaults to None.
        request_parameters(Dict, optional): A key-value map defining required or optional method request parameters that can be accepted by
            API Gateway. A key defines a method request parameter name matching the pattern of
            method.request.{location}.{name}, where location is querystring, path, or header and name is a
            valid and unique parameter name. The value associated with the key is a Boolean flag indicating
            whether the parameter is required (true) or optional (false). The method request parameter names
            defined here are available in Integration to be mapped to integration request parameters or
            body-mapping templates. Defaults to None.
        request_models(Dict, optional): Specifies the Model resources used for the request's content type. Request models are
            represented as a key/value map, with a content type as the key and a Model name as the value. Defaults to None.
        request_validator_id(Text, optional): The identifier of a RequestValidator for validating the method request. Defaults to None.
        authorization_scopes(List, optional): A list of authorization scopes configured on the method. The scopes are used with a
            COGNITO_USER_POOLS authorizer to authorize the method invocation. The authorization works by
            matching the method scopes against the scopes parsed from the access token in the incoming
            request. The method invocation is authorized if any method scopes matches a claimed scope in the
            access token. Otherwise, the invocation is not authorized. When the method scope is configured,
            the client must provide an access token instead of an identity token for authorization purposes. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.apigateway.method.present:
                - name: value
                - rest_api_id: value
                - resource_id: value
                - http_method: value
                - authorization_type: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.apigateway.method.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_method(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.apigateway.put_method(
                ctx,
                
                
                **{"restApiId": rest_api_id, "resourceId": resource_id, "httpMethod": http_method, "authorizationType": authorization_type, "authorizerId": authorizer_id, "apiKeyRequired": api_key_required, "operationName": operation_name, "requestParameters": request_parameters, "requestModels": request_models, "requestValidatorId": request_validator_id, "authorizationScopes": authorization_scopes}
            )
            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_method(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, rest_api_id: Text, resource_id: Text, http_method: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an existing Method 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.
        resource_id(Text): [Required] The Resource identifier for the Method resource.
        http_method(Text): [Required] The HTTP verb of the Method resource.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

