export type Event = {
  _id: string;
  key: string;
  eventName: string;
  environment: string;
  payload: any;
  query?: any;
  headers?: any;
  createdAt: number;
  state: string;
  history: HistoryRecord[];
  ttl: number;
  v: number;
  ownership: {
    buildableId: string;
    userId: string;
    clientId: string;
  },
  processing: {
    hasTransactions: boolean | null;
    totalTransactions: number | null;
    hasFutureTransactions: boolean;
    isCompleted: boolean;
  }
}

export type Transaction = {
  _id: string;
  key: string;
  txn: string;
  event: {
    _id: string;
    eventName: string;
  },
  createdAt: number;
  ttl: number;
  state: string;
  history: HistoryRecord[],
  startedAt: number;
  txKey: string;
  endedAt?: number;
  input: string;
}

export type HistoryRecord = {
  enterState: string;
  exitState: string;
  timestamp: number;
  updatedBy: string;
}


export type OnOptions = {
  platform?: string;
  label?: string;
  txKey?: string;
  since?: number;
}

export type TransactionInput = {
  payload?: any;
  headers?: any;
  query?: any;
  event?: Event;
}

export type ListenerIdInfo = {
  eventName: string;
  txKey: string;
  platform: string;
  label: string;
}

export type OnHandler = (props: TransactionInput) => Promise<any>

export type DeRegisterInfo = {
  eventName?: string;
  txKey?: string;
  platform?: string;
  label?: string;
}