// Mock数据 - 用于agentSelectModifyAddAspect接口
// 模拟用户输入新维度后，所有agent在该维度上的评分数据

import { vueAgentList } from './AgentAssignmentMock'

// 类型定义
export interface NewDimensionScore {
  score: number
  reason: string
}

export type NewDimensionScoreData = Record<string, NewDimensionScore>

// 模拟接口返回的数据结构
export interface AgentAddAspectResponse {
  aspectName: string // 新添加的维度名称
  agentScores: NewDimensionScoreData // 所有agent在该维度上的评分
}

// 生成指定维度名称的mock评分数据
export const generateMockDimensionScores = (dimensionName: string): AgentAddAspectResponse => {
  const agentScores: NewDimensionScoreData = {}

  vueAgentList.forEach((agent) => {
    // 随机生成1-5的评分
    const score = Math.floor(Math.random() * 5) + 1

    // 根据评分生成不同的原因描述
    let reason = ''
    switch (score) {
      case 5:
        reason = `在"${dimensionName}"方面表现卓越，展现出杰出的能力和深刻的理解`
        break
      case 4:
        reason = `在"${dimensionName}"方面表现优秀，具有良好的专业能力和执行力`
        break
      case 3:
        reason = `在"${dimensionName}"方面表现合格，能够完成相关任务`
        break
      case 2:
        reason = `在"${dimensionName}"方面表现一般，仍有提升空间`
        break
      case 1:
        reason = `在"${dimensionName}"方面需要加强，建议进一步提升相关能力`
        break
    }

    agentScores[agent] = { score, reason }
  })

  return {
    aspectName: dimensionName,
    agentScores,
  }
}

// 预设的一些常用维度及其评分数据
export const presetDimensionScores: Record<string, AgentAddAspectResponse> = {
  创新性: generateMockDimensionScores('创新性'),
  技术能力: generateMockDimensionScores('技术能力'),
  沟通技巧: generateMockDimensionScores('沟通技巧'),
  问题解决: generateMockDimensionScores('问题解决'),
  团队协作: generateMockDimensionScores('团队协作'),
  学习能力: generateMockDimensionScores('学习能力'),
  执行力: generateMockDimensionScores('执行力'),
  责任心: generateMockDimensionScores('责任心'),
  适应性: generateMockDimensionScores('适应性'),
  领导力: generateMockDimensionScores('领导力'),
}

// 模拟API调用函数（用于前端测试）
export const mockAgentAddAspectApi = async (
  aspectList: string[],
): Promise<AgentAddAspectResponse[]> => {
  // 获取新增的维度（最后一个）
  const newAspect = aspectList[aspectList.length - 1]

  // 模拟网络延迟 500ms
  await new Promise((resolve) => setTimeout(resolve, 20000))

  // 如果是预设维度，返回预设数据
  if (presetDimensionScores[newAspect]) {
    return [presetDimensionScores[newAspect]]
  }

  // 否则动态生成新的评分数据
  return [generateMockDimensionScores(newAspect)]
}

// Vue Composition API 兼容的hook
export const useAgentAddAspectMock = () => {
  const addNewDimension = async (dimensionName: string) => {
    const response = await mockAgentAddAspectApi([dimensionName])
    return response[0]
  }

  const getMultipleDimensions = async (dimensionNames: string[]) => {
    const responses: AgentAddAspectResponse[] = []

    for (const dimension of dimensionNames) {
      if (presetDimensionScores[dimension]) {
        responses.push(presetDimensionScores[dimension])
      } else {
        responses.push(generateMockDimensionScores(dimension))
      }
    }

    return responses
  }

  return {
    addNewDimension,
    getMultipleDimensions,
    generateMockDimensionScores,
  }
}
