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

hub.exec.boto3.client.autoscaling_plans.create_scaling_plan
hub.exec.boto3.client.autoscaling_plans.delete_scaling_plan
hub.exec.boto3.client.autoscaling_plans.describe_scaling_plans
hub.exec.boto3.client.autoscaling_plans.update_scaling_plan
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, scaling_plan_name: Text, application_source: Dict, scaling_instructions: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a scaling plan.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        scaling_plan_name(Text): The name of the scaling plan. Names cannot contain vertical bars, colons, or forward slashes.
        application_source(Dict): A CloudFormation stack or set of tags. You can create one scaling plan per application source.
            For more information, see ApplicationSource in the AWS Auto Scaling API Reference.
        scaling_instructions(List): The scaling instructions. For more information, see ScalingInstruction in the AWS Auto Scaling
            API Reference.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.autoscaling_plans.scaling_plan.present:
                - name: value
                - scaling_plan_name: value
                - application_source: value
                - scaling_instructions: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.autoscaling_plans.scaling_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.autoscaling_plans.describe_scaling_plans(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.autoscaling_plans.create_scaling_plan(
                ctx,
                
                
                **{"ScalingPlanName": scaling_plan_name, "ApplicationSource": application_source, "ScalingInstructions": scaling_instructions}
            )
            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.autoscaling_plans.describe_scaling_plans(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, scaling_plan_name: Text, scaling_plan_version: int)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified scaling plan. Deleting a scaling plan deletes the underlying ScalingInstruction for all of
    the scalable resources that are covered by the plan. If the plan has launched resources or has scaling
    activities in progress, you must delete those resources separately.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        scaling_plan_name(Text): The name of the scaling plan.
        scaling_plan_version(int): The version number of the scaling plan. Currently, the only valid value is 1.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.autoscaling_plans.scaling_plan.absent:
                - name: value
                - scaling_plan_name: value
                - scaling_plan_version: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.autoscaling_plans.scaling_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.autoscaling_plans.describe_scaling_plans(name)

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

