import { createCodec, Enum } from 'scale-ts';
import { mapObject } from '@pezkuwi/papi-utils';
import { Enum as Enum$1 } from '../../types/enum.mjs';
import { withInner } from './with-inner.mjs';

const VariantEnc = (...args) => {
  const enc = Enum.enc(...args);
  return withInner((v) => enc({ tag: v.type, value: v.value }), args[0]);
};
const VariantDec = (...args) => {
  const dec = Enum.dec(...args);
  return withInner((v) => {
    const { tag, value } = dec(v);
    return Enum$1(tag, value);
  }, args[0]);
};
const Variant = (inner, ...args) => withInner(
  createCodec(
    VariantEnc(
      mapObject(inner, ([encoder]) => encoder),
      ...args
    ),
    VariantDec(
      mapObject(inner, ([, decoder]) => decoder),
      ...args
    )
  ),
  inner
);
Variant.enc = VariantEnc;
Variant.dec = VariantDec;
const ScaleEnum = (inner, ...args) => withInner(Enum(inner, ...args), inner);
ScaleEnum.enc = (inner, ...rest) => withInner(Enum.enc(inner, ...rest), inner);
ScaleEnum.dec = (inner, ...rest) => withInner(Enum.dec(inner, ...rest), inner);

export { ScaleEnum, Variant };
//# sourceMappingURL=Variant.mjs.map
