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

hub.exec.boto3.client.events.create_partner_event_source
hub.exec.boto3.client.events.delete_partner_event_source
hub.exec.boto3.client.events.describe_partner_event_source
hub.exec.boto3.client.events.list_partner_event_sources
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, account: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Called by an SaaS partner to create a partner event source. This operation is not used by Amazon Web Services
    customers. Each partner event source can be used by one Amazon Web Services account to create a matching partner
    event bus in that Amazon Web Services account. A SaaS partner must create one partner event source for each
    Amazon Web Services account that wants to receive those event types.  A partner event source creates events
    based on resources within the SaaS partner's service or application. An Amazon Web Services account that creates
    a partner event bus that matches the partner event source can use that event bus to receive events from the
    partner, and then process them using Amazon Web Services Events rules and targets. Partner event source names
    follow this format:   partner_name/event_namespace/event_name    partner_name is determined during partner
    registration and identifies the partner to Amazon Web Services customers. event_namespace is determined by the
    partner and is a way for the partner to categorize their events. event_name is determined by the partner, and
    should uniquely identify an event-generating resource within the partner system. The combination of
    event_namespace and event_name should help Amazon Web Services customers decide whether to create an event bus
    to receive these events.

    Args:
        name(Text): The name of the partner event source. This name must be unique and must be in the format
            partner_name/event_namespace/event_name . The Amazon Web Services account that wants to use this
            partner event source must create a partner event bus with a name that matches the name of the
            partner event source.
        account(Text): The Amazon Web Services account ID that is permitted to create a matching partner event bus for
            this partner event source.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, account: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    This operation is used by SaaS partners to delete a partner event source. This operation is not used by Amazon
    Web Services customers. When you delete an event source, the status of the corresponding partner event bus in
    the Amazon Web Services customer account becomes DELETED.

    Args:
        name(Text): The name of the event source to delete.
        account(Text): The Amazon Web Services account ID of the Amazon Web Services customer that the event source was
            created for.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

