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

hub.exec.boto3.client.apigateway.create_usage_plan
hub.exec.boto3.client.apigateway.delete_usage_plan
hub.exec.boto3.client.apigateway.get_usage_plans
hub.exec.boto3.client.apigateway.update_usage_plan
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, description: Text = None, api_stages: List = None, throttle: Dict = None, quota: Dict = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a usage plan with the throttle and quota limits, as well as the associated API stages, specified in the
    payload.

    Args:
        name(Text): [Required] The name of the usage plan.
        description(Text, optional): The description of the usage plan. Defaults to None.
        api_stages(List, optional): The associated API stages of the usage plan. Defaults to None.
        throttle(Dict, optional): The throttling limits of the usage plan. Defaults to None.
        quota(Dict, optional): The quota of the usage plan. 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.usage_plan.present:
                - name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.apigateway.usage_plan.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_usage_plans(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.apigateway.create_usage_plan(
                ctx,
                
                
                **{"Name": name, "description": description, "apiStages": api_stages, "throttle": throttle, "quota": quota, "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_usage_plans(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, usage_plan_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a usage plan of a given plan Id.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        usage_plan_id(Text): [Required] The Id of the to-be-deleted usage plan.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

