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

hub.exec.boto3.client.ssm_incidents.create_response_plan
hub.exec.boto3.client.ssm_incidents.delete_response_plan
hub.exec.boto3.client.ssm_incidents.get_response_plan
hub.exec.boto3.client.ssm_incidents.list_response_plans
hub.exec.boto3.client.ssm_incidents.update_response_plan
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, incident_template: Dict, actions: List = None, chat_channel: Dict = None, client_token: Text = None, display_name: Text = None, engagements: List = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a response plan that automates the initial response to incidents. A response plan engages contacts,
    starts chat channel collaboration, and initiates runbooks at the beginning of an incident.

    Args:
        name(Text): The short format name of the response plan. Can't include spaces.
        actions(List, optional): The actions that the response plan starts at the beginning of an incident. Defaults to None.
        chat_channel(Dict, optional): The AWS Chatbot chat channel used for collaboration during an incident. Defaults to None.
        client_token(Text, optional): A token ensuring that the action is called only once with the specified details. Defaults to None.
        display_name(Text, optional): The long format of the response plan name. This field can contain spaces. Defaults to None.
        engagements(List, optional): The contacts and escalation plans that the response plan engages during an incident. Defaults to None.
        incident_template(Dict): Details used to create an incident when using this response plan.
        tags(Dict, optional): A list of tags that you are adding to the response plan. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ssm_incidents.response_plan.present:
                - name: value
                - incident_template: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ssm_incidents.response_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.ssm_incidents.get_response_plan(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ssm_incidents.create_response_plan(
                ctx,
                
                
                **{"Name": name, "actions": actions, "chatChannel": chat_channel, "clientToken": client_token, "displayName": display_name, "engagements": engagements, "incidentTemplate": incident_template, "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.ssm_incidents.get_response_plan(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified response plan. Deleting a response plan stops all linked CloudWatch alarms and EventBridge
    events from creating an incident with this response plan.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        arn(Text): The Amazon Resource Name (ARN) of the response plan.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.ssm_incidents.response_plan.absent:
                - name: value
                - arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ssm_incidents.response_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.ssm_incidents.get_response_plan(name)

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

