import { HexBigInt } from '../../../../shared';
import { HISTORY_CODES } from '../codes';

import {
  CollateralHistoryCode,
  ErrorHistoryCode,
  L1TxHistoryCode,
  ShortHistoryCode,
  UntypedHistoryCode,
} from './codes';

export type ShortHistoryItem<TCode extends ShortHistoryCode = ShortHistoryCode> = {
  code: TCode;
  links?: HistoryLink[] | null;
};

export type ExpandedHistoryItem<TCode extends UntypedHistoryCode = UntypedHistoryCode> = {
  code: TCode;
  message: string;
  links?: HistoryLink[] | null;
};

export type CollateralHistoryItem<TCode extends CollateralHistoryCode = CollateralHistoryCode> = {
  code: TCode;
  message?: string;
  amount: HexBigInt;
  links?: HistoryLink[] | null;
};

export type L1TxHistoryItem<TCode extends L1TxHistoryCode = L1TxHistoryCode> = {
  code: TCode;
  message?: string;
  l1TxId: string;
  links?: HistoryLink[] | null;
};

export type HistoryItem = ShortHistoryItem | ExpandedHistoryItem | CollateralHistoryItem | L1TxHistoryItem;
export type ErrorHistoryItem =
  | ShortHistoryItem<ShortHistoryCode & ErrorHistoryCode>
  | ExpandedHistoryItem<UntypedHistoryCode & ErrorHistoryCode>
  | CollateralHistoryItem<CollateralHistoryCode & ErrorHistoryCode>
  | L1TxHistoryItem<L1TxHistoryCode & ErrorHistoryCode>;

export type HistoryAccess = {
  historyId: string;
  timestamp?: number;
};

export type HistoryLink = Required<HistoryAccess> & {
  code: HISTORY_CODES;
};
