/* eslint-disable max-classes-per-file */
import { ApiDefinitions } from '@api-client/core/build/browser.js';
import { EventTypes } from './EventTypes.js';
import { ApiStoreReadEvent } from './BaseEvents.js';

export const RequestEvents = {
  /**
   * Reads a Request from the store.
   * @param target The node on which to dispatch the event
   * @param id The id of the request to read.
   */
  get: async (target: EventTarget, id: string): Promise<ApiDefinitions.IApiRequest> => {
    const e = new ApiStoreReadEvent(EventTypes.Request.get, id);
    target.dispatchEvent(e);
    return e.detail.result as Promise<ApiDefinitions.IApiRequest>;
  },
}
