type EnumWithExtraInfo<T> = {
  label: string;
  value: T;
  // 可以添加其他额外的信息字段
  tagType?: string;
};

type EnumLabelMap<T> = Record<string, EnumWithExtraInfo<T>>;

export default function createEnumUtils<T extends number | string>(enumValues: EnumWithExtraInfo<T>[]) {
  const enumLabelMap: EnumLabelMap<T> = {} as EnumLabelMap<T>;

  enumValues.forEach(enumValue => {
    const { label, value, ...extraInfo } = enumValue;
    enumLabelMap[label] = { label, value, ...extraInfo };
    enumLabelMap[String(value)] = { label, value, ...extraInfo };
  });

  return {
    getAllEnumValues: (): EnumWithExtraInfo<T>[] => enumValues,
    getLabelByValue: (value: T): string | undefined => enumLabelMap[String(value)]?.label,
    getValueByLabel: (label: string): EnumWithExtraInfo<T> | undefined => enumLabelMap[label]
  };
}
