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

hub.exec.boto3.client.appintegrations.create_event_integration
hub.exec.boto3.client.appintegrations.delete_event_integration
hub.exec.boto3.client.appintegrations.get_event_integration
hub.exec.boto3.client.appintegrations.list_event_integrations
hub.exec.boto3.client.appintegrations.update_event_integration
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, event_filter: Dict, event_bridge_bus: Text, description: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an EventIntegration, given a specified name, description, and a reference to an Amazon EventBridge bus
    in your account and a partner event source that pushes events to that bus. No objects are created in the your
    account, only metadata that is persisted on the EventIntegration control plane.

    Args:
        name(Text): The name of the event integration.
        description(Text, optional): The description of the event integration. Defaults to None.
        event_filter(Dict): The event filter.
        event_bridge_bus(Text): The EventBridge bus.
        tags(Dict, optional): One or more tags. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.appintegrations.create_event_integration(
                ctx,
                
                ClientToken=name,
                **{"Name": name, "Description": description, "EventFilter": event_filter, "EventBridgeBus": event_bridge_bus, "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.appintegrations.get_event_integration(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 existing event integration. If the event integration is associated with clients, the
    request is rejected.

    Args:
        name(Text): The name of the event integration.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

