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

hub.exec.boto3.client.redshift.create_snapshot_schedule
hub.exec.boto3.client.redshift.delete_snapshot_schedule
hub.exec.boto3.client.redshift.describe_snapshot_schedules
hub.exec.boto3.client.redshift.modify_snapshot_schedule
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, schedule_definitions: List = None, schedule_identifier: Text = None, schedule_description: Text = None, tags: List = None, next_invocations: int = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create a snapshot schedule that can be associated to a cluster and which overrides the default system backup
    schedule.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        schedule_definitions(List, optional): The definition of the snapshot schedule. The definition is made up of schedule expressions, for
            example "cron(30 12 *)" or "rate(12 hours)". Defaults to None.
        schedule_identifier(Text, optional): A unique identifier for a snapshot schedule. Only alphanumeric characters are allowed for the
            identifier. Defaults to None.
        schedule_description(Text, optional): The description of the snapshot schedule. Defaults to None.
        tags(List, optional): An optional set of tags you can use to search for the schedule. Defaults to None.
        next_invocations(int, optional): . Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.redshift.create_snapshot_schedule(
                ctx,
                DryRun=ctx.test,
                
                **{"ScheduleDefinitions": schedule_definitions, "ScheduleIdentifier": schedule_identifier, "ScheduleDescription": schedule_description, "Tags": tags, "NextInvocations": next_invocations}
            )
            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.redshift.describe_snapshot_schedules(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        schedule_identifier(Text): A unique identifier of the snapshot schedule to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

