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

hub.exec.boto3.client.ssm.create_maintenance_window
hub.exec.boto3.client.ssm.delete_maintenance_window
hub.exec.boto3.client.ssm.describe_maintenance_windows
hub.exec.boto3.client.ssm.get_maintenance_window
hub.exec.boto3.client.ssm.update_maintenance_window
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, schedule: Text, duration: int, cutoff: int, allow_unassociated_targets: bool, description: Text = None, start_date: Text = None, end_date: Text = None, schedule_timezone: Text = None, schedule_offset: int = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new maintenance window.  The value you specify for Duration determines the specific end time for the
    maintenance window based on the time it begins. No maintenance window tasks are permitted to start after the
    resulting endtime minus the number of hours you specify for Cutoff. For example, if the maintenance window
    starts at 3 PM, the duration is three hours, and the value you specify for Cutoff is one hour, no maintenance
    window tasks can start after 5 PM.

    Args:
        name(Text): The name of the maintenance window.
        description(Text, optional): An optional description for the maintenance window. We recommend specifying a description to
            help you organize your maintenance windows. Defaults to None.
        start_date(Text, optional): The date and time, in ISO-8601 Extended format, for when you want the maintenance window to
            become active. StartDate allows you to delay activation of the maintenance window until the
            specified future date. Defaults to None.
        end_date(Text, optional): The date and time, in ISO-8601 Extended format, for when you want the maintenance window to
            become inactive. EndDate allows you to set a date and time in the future when the maintenance
            window will no longer run. Defaults to None.
        schedule(Text): The schedule of the maintenance window in the form of a cron or rate expression.
        schedule_timezone(Text, optional): The time zone that the scheduled maintenance window executions are based on, in Internet
            Assigned Numbers Authority (IANA) format. For example: "America/Los_Angeles", "UTC", or
            "Asia/Seoul". For more information, see the Time Zone Database on the IANA website. Defaults to None.
        schedule_offset(int, optional): The number of days to wait after the date and time specified by a cron expression before running
            the maintenance window. For example, the following cron expression schedules a maintenance
            window to run on the third Tuesday of every month at 11:30 PM.  cron(30 23 ? * TUE#3 *)  If the
            schedule offset is 2, the maintenance window won't run until two days later. Defaults to None.
        duration(int): The duration of the maintenance window in hours.
        cutoff(int): The number of hours before the end of the maintenance window that Amazon Web Services Systems
            Manager stops scheduling new tasks for execution.
        allow_unassociated_targets(bool): Enables a maintenance window task to run on managed instances, even if you haven't registered
            those instances as targets. If enabled, then you must specify the unregistered instances (by
            instance ID) when you register a task with the maintenance window. If you don't enable this
            option, then you must specify previously-registered targets when you register a task with the
            maintenance window.
        tags(List, optional): Optional metadata that you assign to a resource. Tags enable you to categorize a resource in
            different ways, such as by purpose, owner, or environment. For example, you might want to tag a
            maintenance window to identify the type of tasks it will run, the types of targets, and the
            environment it will run in. In this case, you could specify the following key-value pairs:
            Key=TaskType,Value=AgentUpdate     Key=OS,Value=Windows     Key=Environment,Value=Production
            To add tags to an existing maintenance window, use the AddTagsToResource operation. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ssm.maintenance_window.present:
                - name: value
                - schedule: value
                - duration: value
                - cutoff: value
                - allow_unassociated_targets: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ssm.maintenance_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.ssm.describe_maintenance_windows(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ssm.create_maintenance_window(
                ctx,
                
                ClientToken=name,
                **{"Name": name, "Description": description, "StartDate": start_date, "EndDate": end_date, "Schedule": schedule, "ScheduleTimezone": schedule_timezone, "ScheduleOffset": schedule_offset, "Duration": duration, "Cutoff": cutoff, "AllowUnassociatedTargets": allow_unassociated_targets, "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.describe_maintenance_windows(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, window_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a maintenance window.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        window_id(Text): The ID of the maintenance window to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.ssm.maintenance_window.absent:
                - name: value
                - window_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ssm.maintenance_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.ssm.describe_maintenance_windows(name)

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

