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

hub.exec.boto3.client.ec2.associate_instance_event_window
hub.exec.boto3.client.ec2.create_instance_event_window
hub.exec.boto3.client.ec2.delete_instance_event_window
hub.exec.boto3.client.ec2.describe_instance_event_windows
hub.exec.boto3.client.ec2.disassociate_instance_event_window
hub.exec.boto3.client.ec2.modify_instance_event_window
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text = None, time_ranges: List = None, cron_expression: Text = None, tag_specifications: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an event window in which scheduled events for the associated Amazon EC2 instances can run. You can
    define either a set of time ranges or a cron expression when creating the event window, but not both. All event
    window times are in UTC. You can create up to 200 event windows per Amazon Web Services Region. When you create
    the event window, targets (instance IDs, Dedicated Host IDs, or tags) are not yet associated with it. To ensure
    that the event window can be used, you must associate one or more targets with it by using the
    AssociateInstanceEventWindow API.  Event windows are applicable only for scheduled events that stop, reboot, or
    terminate instances. Event windows are not applicable for:   Expedited scheduled events and network maintenance
    events.    Unscheduled maintenance such as AutoRecovery and unplanned reboots.    For more information, see
    Define event windows for scheduled events in the Amazon EC2 User Guide.

    Args:
        name(Text, optional): The name of the event window. Defaults to None.
        time_ranges(List, optional): The time range for the event window. If you specify a time range, you can't specify a cron
            expression. Defaults to None.
        cron_expression(Text, optional): The cron expression for the event window, for example, * 0-4,20-23 * * 1,5. If you specify a
            cron expression, you can't specify a time range. Constraints:   Only hour and day of the week
            values are supported.   For day of the week values, you can specify either integers 0 through 6,
            or alternative single values SUN through SAT.   The minute, month, and year must be specified by
            *.   The hour value must be one or a multiple range, for example, 0-4 or 0-4,20-23.   Each hour
            range must be >= 2 hours, for example, 0-2 or 20-23.   The event window must be >= 4 hours. The
            combined total time ranges in the event window must be >= 4 hours.   For more information about
            cron expressions, see cron on the Wikipedia website. Defaults to None.
        tag_specifications(List, optional): The tags to apply to the event window. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ec2.instance_event_window.present:
                - 
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.instance_event_window.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.ec2.describe_instance_event_windows(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_instance_event_window(
                ctx,
                DryRun=ctx.test,
                
                **{"Name": name, "TimeRanges": time_ranges, "CronExpression": cron_expression, "TagSpecifications": tag_specifications}
            )
            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.ec2.describe_instance_event_windows(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, instance_event_window_id: Text, force_delete: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified event window. For more information, see Define event windows for scheduled events in the
    Amazon EC2 User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        force_delete(bool, optional): Specify true to force delete the event window. Use the force delete parameter if the event
            window is currently associated with targets. Defaults to None.
        instance_event_window_id(Text): The ID of the event window.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.delete_instance_event_window(
                ctx,
                DryRun=ctx.test,
                
                **{"ForceDelete": force_delete, "InstanceEventWindowId": instance_event_window_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.ec2.describe_instance_event_windows(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

