import { TSchema, Data } from '@evolution-sdk/evolution';
import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';

const VersionRecordDatumSchema = TSchema.Struct({
  upgradeId: TSchema.Integer,
  /// Underlying representation of the following mapping: ValidatorHash -> UpgradePath
  upgradePaths: TSchema.Array(
    TSchema.Tuple([TSchema.ByteArray, TSchema.ByteArray]),
  ),
});
export type VersionRecordDatum = typeof VersionRecordDatumSchema.Type;

export function serialiseVersionRecordDatum(d: VersionRecordDatum): string {
  return Data.withSchema(
    VersionRecordDatumSchema,
    DEFAULT_SCHEMA_OPTIONS,
  ).toCBORHex(d);
}
