// TODO: 联调时删除此文件，改为真实 API 调用

// ============================================================
// 类型定义
// ============================================================

export type TaskType = 'high_priority_recall' | 'priority_recall' | 'follow_up_visit' | 'relationship_building'

/** 备注评分记录 */
export interface Note {
  id: string
  content: string
  tagType: 'customer' | 'coach' | 'system'
  tagLabel: string
  createdAt: string
  /** 满意度评分 0-10，0 表示未评分 */
  score?: number
  /** 格式化时间标签（由前端附加） */
  timeLabel?: string
}

export interface Task {
  id: string
  customerName: string
  customerAvatar: string
  taskType: TaskType
  taskTypeLabel: string
  deadline: string
  heartScore: number
  hobbies: string[]
  isPinned: boolean
  hasNote: boolean
  status: 'pending' | 'completed' | 'abandoned'
}

export interface TaskDetail extends Task {
  aiAnalysis: { summary: string; suggestions: string[] }
  notes: Note[]
  lastVisitDate?: string
  lastSpendAmount?: number
  callbackReason?: string
  daysAbsent?: number
  spendTrend?: 'up' | 'down' | 'flat'
  churnRisk?: 'high' | 'medium' | 'low'
  preferences?: string[]
  consumptionHabits?: string
  socialPreference?: string
  /** 客户手机号（后端返回） */
  customerPhone?: string
  /** 客户储值余额（元，用于计算储值等级） */
  balance?: number
  /** AI 生成的行动建议列表 */
  actionSuggestions?: string[]
  /** 客户 ID（member_id） */
  customerId?: number
  /** 维客线索 */
  retentionClues?: Array<{
    tag: string
    tagColor: string
    emoji: string
    text: string
    source: string
    desc?: string
  }>
  /** 话术参考 */
  talkingPoints?: string[]
  /** 服务记录汇总 */
  serviceSummary?: {
    totalHours: number
    totalIncome: number
    avgIncome: number
  }
  /** 近期服务记录 */
  serviceRecords?: Array<{
    table: string | null
    type: string
    typeClass: string
    recordType?: string
    duration: number
    durationRaw?: number
    income: number
    isEstimate?: boolean
    drinks?: string | null
    date: string
  }>
}

export interface Note {
  id: string
  /** 备注正文 */
  content: string
  /** 标签类型：customer=客户备注，coach=助教备注 */
  tagType: 'customer' | 'coach'
  /** 标签文案，如"客户：王先生"、"助教：小燕" */
  tagLabel: string
  /** 创建时间，展示用格式 */
  createdAt: string
}

export interface RetentionClue {
  id: string
  /** 线索大类 */
  category: 'customer_basic' | 'consumption' | 'play_pref' | 'promo_pref' | 'social' | 'feedback'
  /** 摘要 */
  summary: string
  /** 详情 */
  detail?: string
  /** 线索来源：manual=助教手动，ai_consumption=系统自动，ai_note=备注分析 */
  source: 'manual' | 'ai_consumption' | 'ai_note'
  /** 记录助教ID（用于判断是否为"我"） */
  recordedByAssistantId?: string
  /** 记录助教姓名 */
  recordedByName?: string
  /** 创建时间 */
  createdAt: string
}

export interface PerformanceData {
  monthlyIncome: number
  incomeChange: number
  currentTier: string
  nextTierGap: number
  todayServiceCount: number
  weekServiceCount: number
  monthServiceCount: number
}

export interface PerformanceRecord {
  id: string
  customerName: string
  amount: number
  date: string
  type: string
  category: string
}

export interface FinanceMetric {
  title: string
  value: number
  unit: string
  trend: 'up' | 'down' | 'flat'
  trendValue: string
  helpText?: string
}

export interface BoardFinanceData {
  metrics: FinanceMetric[]
  timeRange: string
  filterOptions: Array<{ value: string; text: string }>
  /** P13: AI 智能洞察列表 */
  aiInsights?: Array<{ icon: string; text: string }>
  /** P13: 是否为预估数据 */
  isEstimated?: boolean
}

export interface CustomerCard {
  id: string
  name: string
  avatar: string
  heartScore: number
  tags: string[]
  keyMetric: { label: string; value: string }
}

export interface CoachCard {
  id: string
  name: string
  avatar: string
  level: string
  keyMetrics: Array<{ label: string; value: string }>
  /** P13: 任务执行统计 */
  taskStats?: { recall: number; callback: number }
}

export interface CustomerDetail {
  id: string
  name: string
  avatar: string
  tags: string[]
  heartScore: number
  phone: string
  spiIndex: number
  /** 累计服务次数 */
  totalServiceCount?: number
  consumptionRecords: ConsumptionRecord[]
}

export interface ConsumptionRecord {
  id: string
  date: string
  project: string
  duration: number
  amount: number
  coachName: string
}

export interface ChatMessage {
  id: string
  role: 'user' | 'assistant'
  content: string
  timestamp: string
  referenceCard?: {
    type: 'customer' | 'record'
    title: string
    summary: string
    data: Record<string, string>
  }
}

export interface ChatHistoryItem {
  id: string
  title: string
  lastMessage: string
  timestamp: string
  customerName?: string
}

export interface UserProfile {
  name: string
  avatar: string
  role: string
  storeName: string
}

// ============================================================
// Mock 数据 — 任务模块
// ============================================================

export const mockTasks: Task[] = [
  { id: '', customerName: '', customerAvatar: '', taskType: 'follow_up_visit', taskTypeLabel: '', deadline: '', heartScore: 0, hobbies: [], isPinned: false, hasNote: false, status: 'pending' },
  { id: '', customerName: '', customerAvatar: '', taskType: 'high_priority_recall', taskTypeLabel: '', deadline: '', heartScore: 0, hobbies: [], isPinned: true, hasNote: false, status: 'pending' },
]

export const mockTaskDetails: TaskDetail[] = [
  { id: '', customerName: '', customerAvatar: '', taskType: 'follow_up_visit', taskTypeLabel: '', deadline: '', heartScore: 0, hobbies: [], isPinned: false, hasNote: false, status: 'pending', aiAnalysis: { summary: '', suggestions: ['', ''] }, notes: [{ id: '', content: '', tagType: 'coach', tagLabel: '', createdAt: '' }] },
]

// ============================================================
// Mock 数据 — 维客线索模块
// ============================================================

// 维客线索 MOCK 数据
// 说明：
// - 后端已过滤，客户端直接使用
// - 任务详情页：后端返回脱敏版本（移除 recordedByAssistantId 和 recordedByName）
// - 客户详情页：后端返回完整版本（包含 recordedByAssistantId 和 recordedByName）
// 
// 以下是任务详情页的 MOCK 数据（脱敏版本）
export const mockRetentionClues: RetentionClue[] = [
  { id: '', category: 'customer_basic', summary: '', source: 'ai_consumption', createdAt: '' },
  { id: '', category: 'consumption', summary: '', detail: '', source: 'manual', createdAt: '' },
]

// 客户详情页的 MOCK 数据（完整版本，不脱敏）
export const mockRetentionCluesForCustomerDetail: RetentionClue[] = [
  { id: '', category: 'customer_basic', summary: '', source: 'ai_consumption', recordedByAssistantId: '', recordedByName: '', createdAt: '' },
  { id: '', category: 'feedback', summary: '', detail: '', source: 'manual', recordedByAssistantId: '', recordedByName: '', createdAt: '' },
]

// ============================================================
// Mock 数据 — 备注模块
// ============================================================

// mock 数据贴近 H5 原型 notes.html 中的 12 条备注
export const mockNotes: Note[] = [
  { id: '', content: '', tagType: 'coach', tagLabel: '', createdAt: '' },
  { id: '', content: '', tagType: 'customer', tagLabel: '', createdAt: '' },
]

// ============================================================
// Mock 数据 — 绩效模块
// ============================================================

export const mockPerformance: PerformanceData = {
  monthlyIncome: 0,
  incomeChange: 0,
  currentTier: '',
  nextTierGap: 0,
  todayServiceCount: 0,
  weekServiceCount: 0,
  monthServiceCount: 0,
}

export const mockPerformanceRecords: PerformanceRecord[] = [
  { id: '', customerName: '', amount: 0, date: '', type: '', category: '' },
  { id: '', customerName: '', amount: 0, date: '', type: '', category: '' },
]

// ============================================================
// Mock 数据 — 看板模块
// ============================================================

export const mockBoardFinance: BoardFinanceData = {
  metrics: [
    { title: '', value: 0, unit: '', trend: 'flat', trendValue: '' },
    { title: '', value: 0, unit: '', trend: 'flat', trendValue: '' },
  ],
  timeRange: '',
  filterOptions: [],
}

export const mockCustomers: CustomerCard[] = [
  { id: '', name: '', avatar: '', heartScore: 0, tags: [], keyMetric: { label: '', value: '' } },
  { id: '', name: '', avatar: '', heartScore: 0, tags: [], keyMetric: { label: '', value: '' } },
]

export const mockCoaches: CoachCard[] = [
  { id: '', name: '', avatar: '', level: '', keyMetrics: [{ label: '', value: '' }] },
  { id: '', name: '', avatar: '', level: '', keyMetrics: [{ label: '', value: '' }] },
]

// ============================================================
// Mock 数据 — 客户详情模块
// ============================================================

export const mockCustomerDetail: CustomerDetail = {
  id: '',
  name: '',
  avatar: '',
  tags: [''],
  heartScore: 0,
  phone: '',
  spiIndex: 0,
  consumptionRecords: [
    { id: '', date: '', project: '', duration: 0, amount: 0, coachName: '' },
    { id: '', date: '', project: '', duration: 0, amount: 0, coachName: '' },
  ],
}

// ============================================================
// Mock 数据 — 对话模块
// ============================================================

export const mockChatMessages: ChatMessage[] = [
  { id: '', role: 'user', content: '', timestamp: '' },
  { id: '', role: 'assistant', content: '', timestamp: '' },
]

export const mockChatHistory: ChatHistoryItem[] = [
  { id: '', title: '', lastMessage: '', timestamp: '', customerName: '' },
  { id: '', title: '', lastMessage: '', timestamp: '' },
]

// ============================================================
// Mock 数据 — 用户信息
// ============================================================

export const mockUserProfile: UserProfile = {
  name: '',
  avatar: '',
  role: '',
  storeName: '',
}
