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

hub.exec.boto3.client.events.create_event_bus
hub.exec.boto3.client.events.delete_event_bus
hub.exec.boto3.client.events.describe_event_bus
hub.exec.boto3.client.events.list_event_buses
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, event_source_name: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new event bus within your account. This can be a custom event bus which you can use to receive events
    from your custom applications and services, or it can be a partner event bus which can be matched to a partner
    event source.

    Args:
        name(Text): The name of the new event bus.  Event bus names cannot contain the / character. You can't use
            the name default for a custom event bus, as this name is already used for your account's default
            event bus. If this is a partner event bus, the name must exactly match the name of the partner
            event source that this event bus is matched to.
        event_source_name(Text, optional): If you are creating a partner event bus, this specifies the partner event source that the new
            event bus will be matched with. Defaults to None.
        tags(List, optional): Tags to associate with the event bus. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.events.create_event_bus(
                ctx,
                
                
                **{"Name": name, "EventSourceName": event_source_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.events.describe_event_bus(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified custom event bus or partner event bus. All rules associated with this event bus need to be
    deleted. You can't delete your account's default event bus.

    Args:
        name(Text): The name of the event bus to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

