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

hub.exec.boto3.client.ssm_incidents.create_timeline_event
hub.exec.boto3.client.ssm_incidents.delete_timeline_event
hub.exec.boto3.client.ssm_incidents.get_timeline_event
hub.exec.boto3.client.ssm_incidents.list_timeline_events
hub.exec.boto3.client.ssm_incidents.update_timeline_event
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, event_data: Text, event_time: Text, event_type: Text, incident_record_arn: Text, client_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a custom timeline event on the incident details page of an incident record. Timeline events are
    automatically created by Incident Manager, marking key moment during an incident. You can create custom timeline
    events to mark important events that are automatically detected by Incident Manager.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        client_token(Text, optional): A token ensuring that the action is called only once with the specified details. Defaults to None.
        event_data(Text): A valid JSON string. There is no other schema imposed. A short description of the event.
        event_time(Text): The time that the event occurred.
        event_type(Text): The type of the event. You can create timeline events of type Custom Event.
        incident_record_arn(Text): The Amazon Resource Name (ARN) of the incident record you are adding the event to.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ssm_incidents.timeline_event.present:
                - name: value
                - event_data: value
                - event_time: value
                - event_type: value
                - incident_record_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ssm_incidents.timeline_event.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_timeline_event(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ssm_incidents.create_timeline_event(
                ctx,
                
                
                **{"clientToken": client_token, "eventData": event_data, "eventTime": event_time, "eventType": event_type, "incidentRecordArn": incident_record_arn}
            )
            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_timeline_event(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, event_id: Text, incident_record_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a timeline event from an incident.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        event_id(Text): The ID of the event you are updating. You can find this by using ListTimelineEvents.
        incident_record_arn(Text): The Amazon Resource Name (ARN) of the incident that the event is part of.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

