import { Claim, ClaimKey, OrdJson } from '@coinweb/contract-kit';

export type HexBigInt = `0x${string}`;

export type HexToBigInt<T> = T extends object
  ? { [K in keyof T]: HexToBigInt<T[K]> }
  : T extends unknown[]
    ? HexToBigInt<T[number]>[]
    : T extends HexBigInt
      ? bigint
      : T;

export type BigIntToHex<T> = T extends object
  ? { [K in keyof T]: BigIntToHex<T[K]> }
  : T extends unknown[]
    ? BigIntToHex<T[number]>[]
    : T extends bigint
      ? HexBigInt
      : T;

export type TypedClaim<TBody extends OrdJson, TKey extends ClaimKey = ClaimKey> = Claim & {
  body: TBody;
  fees_stored: HexBigInt;
  key: TKey;
};

export type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void
  ? I
  : never;

export type MergePartialWithRegular<
  GPartial extends Record<string, unknown>,
  GRegular extends Record<string, unknown>,
> = Partial<Omit<GPartial, keyof GRegular>> & GRegular;
