export const roleOptions = [
  { label: '超级管理员', value: 'SUPER_ADMIN' },
  { label: '运营专员', value: 'OPERATOR' },
  { label: '财务人员', value: 'FINANCE' },
  { label: '只读人员', value: 'READONLY' },
];

const roleMap: Record<string, string> = Object.fromEntries(roleOptions.map((item) => [item.value, item.label]));

const operationMap: Record<string, string> = {
  recharge: '充值入账',
  manual_recharge: '手动充值',
  outline_generate: '大纲生成',
  storyboard_generate: '分镜生成',
  script_generate: '剧本生成',
  image_generate: '图片生成',
  video_generate: '视频生成',
  structured_video: '剧本成片',
  ref_image_to_video: '参考图成片',
  image_to_video: '图片成片',
  text_to_video: '文案成片',
  text_generate: '文本生成',
  audio_generate: '配音生成',
  asset_generate: '素材生成',
};

const modalityMap: Record<string, string> = {
  TEXT: '文本',
  IMAGE: '图片',
  VIDEO: '视频',
  AUDIO: '音频',
  RECHARGE: '充值',
};

const providerMap: Record<string, string> = {
  volcengine: '火山方舟',
  qwen: '通义千问',
  openai: 'OpenAI',
  local: '本地模型',
};

const billingModeMap: Record<string, string> = {
  STRICT: '严格扣费',
  SOFT: '运营补录',
  FREE: '免费额度',
};

function humanizeCode(value?: string) {
  if (!value) return '-';
  return value
    .replace(/^doubao-/i, '豆包 ')
    .replace(/^qwen-/i, '通义千问 ')
    .replace(/seedance/i, 'Seedance')
    .replace(/seedream/i, 'Seedream')
    .replace(/structured video/i, '剧本成片')
    .replace(/ref image to video/i, '参考图成片')
    .replace(/image to video/i, '图片成片')
    .replace(/text to video/i, '文案成片')
    .replace(/[_-]+/g, ' ')
    .replace(/\bfast\b/gi, '极速版')
    .replace(/\bpro\b/gi, '专业版')
    .replace(/\bturbo\b/gi, 'Turbo')
    .replace(/\btext\b/gi, '文本')
    .replace(/\bimage\b/gi, '图片')
    .replace(/\bvideo\b/gi, '视频')
    .trim();
}

export function displayRole(value?: string) {
  return value ? roleMap[value] || humanizeCode(value) : '-';
}

export function displayOperation(value?: string) {
  return value ? operationMap[value] || humanizeCode(value) : '-';
}

export function displayModality(value?: string) {
  return value ? modalityMap[value] || humanizeCode(value) : '-';
}

export function displayProvider(value?: string) {
  return value ? providerMap[value] || humanizeCode(value) : '-';
}

export function displayBillingMode(value?: string) {
  return value ? billingModeMap[value] || humanizeCode(value) : '-';
}

export function displayModelName(modelName?: string, modelId?: string) {
  return modelName || humanizeCode(modelId);
}
