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

hub.exec.boto3.client.events.create_archive
hub.exec.boto3.client.events.delete_archive
hub.exec.boto3.client.events.describe_archive
hub.exec.boto3.client.events.list_archives
hub.exec.boto3.client.events.update_archive
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, archive_name: Text, event_source_arn: Text, description: Text = None, event_pattern: Text = None, retention_days: int = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an archive of events with the specified settings. When you create an archive, incoming events might not
    immediately start being sent to the archive. Allow a short period of time for changes to take effect. If you do
    not specify a pattern to filter events sent to the archive, all events are sent to the archive except replayed
    events. Replayed events are not sent to an archive.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        archive_name(Text): The name for the archive to create.
        event_source_arn(Text): The ARN of the event bus that sends events to the archive.
        description(Text, optional): A description for the archive. Defaults to None.
        event_pattern(Text, optional): An event pattern to use to filter events sent to the archive. Defaults to None.
        retention_days(int, optional): The number of days to retain events for. Default value is 0. If set to 0, events are retained
            indefinitely. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.events.create_archive(
                ctx,
                
                
                **{"ArchiveName": archive_name, "EventSourceArn": event_source_arn, "Description": description, "EventPattern": event_pattern, "RetentionDays": retention_days}
            )
            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.events.describe_archive(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, archive_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified archive.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

