import {
  DEFAULT_LABEL,
  ENABLE_TYPE,
  ROLE_TYPE,
  EXAM_TYPE,
  MARKING_MODE,
  LOG_TYPE,
  OPTIONAL_SCORE_RULE,
  USER_SOURCE,
  EXAM_STATUS,
} from '@/constants/enumerate';
import { formatDate } from './utils';

// 字典过滤器
export const dictFilter = {
  enable: (val: boolean) =>
    ENABLE_TYPE[val as keyof typeof ENABLE_TYPE] || DEFAULT_LABEL,
  role: (val: string) =>
    ROLE_TYPE[val as keyof typeof ROLE_TYPE] || DEFAULT_LABEL,
  examType: (val: string) =>
    EXAM_TYPE[val as keyof typeof EXAM_TYPE] || DEFAULT_LABEL,
  markingMode: (val: string) =>
    MARKING_MODE[val as keyof typeof MARKING_MODE] || DEFAULT_LABEL,
  logType: (val: string) =>
    LOG_TYPE[val as keyof typeof LOG_TYPE] || DEFAULT_LABEL,
  optionalScoreRule: (val: string) =>
    OPTIONAL_SCORE_RULE[val as keyof typeof OPTIONAL_SCORE_RULE] ||
    DEFAULT_LABEL,
  userSource: (val: string) =>
    USER_SOURCE[val as keyof typeof USER_SOURCE] || DEFAULT_LABEL,
  examStatus: (val: string) =>
    EXAM_STATUS[val as keyof typeof EXAM_STATUS] || DEFAULT_LABEL,
};

// 时间戳过滤器
export function timestampFilter(val: number | null): string {
  return val ? formatDate('YYYY-MM-DD HH:mm:ss', new Date(val)) : DEFAULT_LABEL;
}
