import request from '@/request/alova';
import type { Dictionaries } from '@/core/dictionary/index';



function getRemoteDictionaries(sign: string) {
  return request.Get<Dictionaries, any[]>(`/system/dict/data/type/${sign}`, {
    cacheFor: {
      mode: 'restore',
      expire: 1000 * 60 * 60 * 24,
      tag: __APP_VERSION__,
    },
    transform(data: any[]) {
      return (
        data?.map((item) => ({
          label: item.dictLabel,
          value: item.dictValue,
          default: item.isDefault === 'Y',
        })) ?? []
      );
    },
  });
}

export async function getDictionaries(sign: string) {
  return getRemoteDictionaries(sign);
}