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

hub.exec.boto3.client.iot.create_scheduled_audit
hub.exec.boto3.client.iot.delete_scheduled_audit
hub.exec.boto3.client.iot.describe_scheduled_audit
hub.exec.boto3.client.iot.list_scheduled_audits
hub.exec.boto3.client.iot.update_scheduled_audit
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, frequency: Text, target_check_names: List, scheduled_audit_name: Text, day_of_month: Text = None, day_of_week: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a scheduled audit that is run at a specified time interval.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        frequency(Text): How often the scheduled audit takes place, either DAILY, WEEKLY, BIWEEKLY or MONTHLY. The start
            time of each audit is determined by the system.
        day_of_month(Text, optional): The day of the month on which the scheduled audit takes place. This can be "1" through "31" or
            "LAST". This field is required if the "frequency" parameter is set to MONTHLY. If days 29 to 31
            are specified, and the month doesn't have that many days, the audit takes place on the LAST day
            of the month. Defaults to None.
        day_of_week(Text, optional): The day of the week on which the scheduled audit takes place, either SUN, MON, TUE, WED, THU,
            FRI, or SAT. This field is required if the frequency parameter is set to WEEKLY or BIWEEKLY. Defaults to None.
        target_check_names(List): Which checks are performed during the scheduled audit. Checks must be enabled for your account.
            (Use DescribeAccountAuditConfiguration to see the list of all checks, including those that are
            enabled or use UpdateAccountAuditConfiguration to select which checks are enabled.).
        scheduled_audit_name(Text): The name you want to give to the scheduled audit. (Max. 128 chars).
        tags(List, optional): Metadata that can be used to manage the scheduled audit. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iot.scheduled_audit.present:
                - name: value
                - frequency: value
                - target_check_names: value
                - scheduled_audit_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iot.scheduled_audit.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.iot.describe_scheduled_audit(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iot.create_scheduled_audit(
                ctx,
                
                
                **{"frequency": frequency, "dayOfMonth": day_of_month, "dayOfWeek": day_of_week, "targetCheckNames": target_check_names, "scheduledAuditName": scheduled_audit_name, "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.iot.describe_scheduled_audit(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        scheduled_audit_name(Text): The name of the scheduled audit you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

