// 工时统计模块模型定义

// 项目阶段类型
export type ProjectPhase = '建模' | '渲染' | '后期' | '软装' | '对图' | '修改';

// 项目空间类型
export type SpaceType = '客餐厅' | '卧室' | '厨房' | '卫生间' | '书房' | '阳台' | '玄关' | '别墅';

// 项目风格类型
export type ProjectStyle = '现代简约' | '新中式' | '北欧' | '工业风' | '轻奢' | '美式' | '欧式' | '日式';

// 绩效等级
export type PerformanceLevel = 'S' | 'A' | 'B' | 'C';

// 工时记录状态
export type WorkHourStatus = '工作中' | '停滞' | '等待' | '完成';

// 难度系数配置
export interface DifficultyCoefficient {
  spaceType: SpaceType;
  spaceCoefficient: number; // 空间复杂度系数
  styleType: ProjectStyle;
  styleCoefficient: number; // 风格难度系数
}

// 工时记录
export interface WorkHourRecord {
  id: string;
  projectId: string;
  projectName: string;
  designerId: string;
  designerName: string;
  phase: ProjectPhase;
  startTime: Date;
  endTime?: Date;
  actualHours: number; // 实际工作时间
  status: WorkHourStatus;
  pauseReason?: string; // 停滞原因（如"客户3天未反馈"、"等待渲染1天"）
  pauseHours?: number; // 停滞时间
  spaceType: SpaceType;
  projectStyle: ProjectStyle;
  difficultyCoefficient: number; // 综合难度系数
  effectiveHours: number; // 有效工时 = 实际工作时间 × 难度系数
  notes?: string;
}

// 月度工时统计
export interface MonthlyWorkHourStats {
  designerId: string;
  designerName: string;
  month: string; // YYYY-MM格式
  totalActualHours: number; // 总实际工时
  totalEffectiveHours: number; // 总有效工时
  totalPauseHours: number; // 总停滞时间
  completedProjects: number; // 完成项目数
  averageCustomerSatisfaction: number; // 平均客户满意度
  performanceLevel: PerformanceLevel; // 绩效等级
  onTimeCompletionRate: number; // 按时完成率
  excellentWorkRate: number; // 优秀作品率
  records: WorkHourRecord[]; // 详细记录
}

// 绩效等级标准
export interface PerformanceCriteria {
  level: PerformanceLevel;
  timeCompletionRate: number; // 时间完成率阈值（如提前20%以上为S级）
  customerSatisfactionMin: number; // 客户满意度最低要求
  description: string;
  bonusMultiplier: number; // 奖金系数
}

// 报价规则配置
export interface PricingRule {
  spaceType: SpaceType;
  basePrice: number; // 基础价格（元/人天）
  styleType: ProjectStyle;
  styleMultiplier: number; // 风格系数
  finalPrice: number; // 最终价格 = 基础价格 × 风格系数
  serviceIncludes: string[]; // 包含服务内容
}

// 报价话术
export interface PricingScript {
  id: string;
  category: string; // 话术分类（如"高端报价解释"、"价格构成说明"）
  title: string;
  content: string;
  applicableScenarios: string[]; // 适用场景
  tags: string[];
}

// 自动报价结果
export interface AutoQuotationResult {
  id: string;
  projectId?: string;
  spaceType: SpaceType;
  projectStyle: ProjectStyle;
  estimatedWorkDays: number; // 预估工作天数
  basePrice: number;
  styleMultiplier: number;
  finalPrice: number;
  serviceIncludes: string[];
  createdAt: Date;
  createdBy: string; // 客服ID
  adjustments?: PriceAdjustment[]; // 价格调整记录
  status: 'draft' | 'sent' | 'approved' | 'rejected';
}

// 价格调整记录
export interface PriceAdjustment {
  id: string;
  originalPrice: number;
  adjustedPrice: number;
  reason: string;
  adjustedBy: string; // 调整人ID
  adjustedAt: Date;
  approvedBy?: string; // 审批人ID
  approvedAt?: Date;
}

// 工时统计仪表板数据
export interface WorkHourDashboardData {
  totalDesigners: number;
  totalProjects: number;
  averageEffectiveHours: number;
  performanceDistribution: {
    S: number;
    A: number;
    B: number;
    C: number;
  };
  monthlyTrends: {
    month: string;
    totalHours: number;
    effectiveHours: number;
    efficiency: number; // 效率 = 有效工时 / 总工时
  }[];
  topPerformers: {
    designerId: string;
    designerName: string;
    effectiveHours: number;
    performanceLevel: PerformanceLevel;
    efficiency: number;
  }[];
}

// 默认难度系数配置
export const DEFAULT_DIFFICULTY_COEFFICIENTS: DifficultyCoefficient[] = [
  // 空间类型系数
  { spaceType: '客餐厅', spaceCoefficient: 1.0, styleType: '现代简约', styleCoefficient: 1.0 },
  { spaceType: '卧室', spaceCoefficient: 0.8, styleType: '现代简约', styleCoefficient: 1.0 },
  { spaceType: '厨房', spaceCoefficient: 0.9, styleType: '现代简约', styleCoefficient: 1.0 },
  { spaceType: '卫生间', spaceCoefficient: 0.7, styleType: '现代简约', styleCoefficient: 1.0 },
  { spaceType: '书房', spaceCoefficient: 0.8, styleType: '现代简约', styleCoefficient: 1.0 },
  { spaceType: '阳台', spaceCoefficient: 0.6, styleType: '现代简约', styleCoefficient: 1.0 },
  { spaceType: '玄关', spaceCoefficient: 0.5, styleType: '现代简约', styleCoefficient: 1.0 },
  { spaceType: '别墅', spaceCoefficient: 1.5, styleType: '现代简约', styleCoefficient: 1.0 },
  
  // 风格类型系数
  { spaceType: '客餐厅', spaceCoefficient: 1.0, styleType: '新中式', styleCoefficient: 1.2 },
  { spaceType: '客餐厅', spaceCoefficient: 1.0, styleType: '北欧', styleCoefficient: 1.0 },
  { spaceType: '客餐厅', spaceCoefficient: 1.0, styleType: '工业风', styleCoefficient: 1.1 },
  { spaceType: '客餐厅', spaceCoefficient: 1.0, styleType: '轻奢', styleCoefficient: 1.3 },
  { spaceType: '客餐厅', spaceCoefficient: 1.0, styleType: '美式', styleCoefficient: 1.2 },
  { spaceType: '客餐厅', spaceCoefficient: 1.0, styleType: '欧式', styleCoefficient: 1.4 },
  { spaceType: '客餐厅', spaceCoefficient: 1.0, styleType: '日式', styleCoefficient: 1.1 }
];

// 默认绩效等级标准
export const DEFAULT_PERFORMANCE_CRITERIA: PerformanceCriteria[] = [
  {
    level: 'S',
    timeCompletionRate: 120, // 提前20%以上完成
    customerSatisfactionMin: 5.0,
    description: '提前20%以上完成，客户满意度5分',
    bonusMultiplier: 1.5
  },
  {
    level: 'A',
    timeCompletionRate: 100, // 标准时间内完成
    customerSatisfactionMin: 4.0,
    description: '标准时间内完成，客户满意度4-5分',
    bonusMultiplier: 1.2
  },
  {
    level: 'B',
    timeCompletionRate: 80, // 超时但客户满意度达标
    customerSatisfactionMin: 4.0,
    description: '超时但客户满意度4分以上',
    bonusMultiplier: 1.0
  },
  {
    level: 'C',
    timeCompletionRate: 0, // 多次修改且耗时过长
    customerSatisfactionMin: 0,
    description: '多次修改且耗时过长，客户满意度<4分',
    bonusMultiplier: 0.8
  }
];

// 默认报价规则
export const DEFAULT_PRICING_RULES: PricingRule[] = [
  // 客餐厅
  { spaceType: '客餐厅', basePrice: 600, styleType: '现代简约', styleMultiplier: 1.0, finalPrice: 600, serviceIncludes: ['建模', '渲染', '1次小图修改'] },
  { spaceType: '客餐厅', basePrice: 600, styleType: '新中式', styleMultiplier: 1.2, finalPrice: 720, serviceIncludes: ['建模', '渲染', '1次小图修改'] },
  { spaceType: '客餐厅', basePrice: 600, styleType: '轻奢', styleMultiplier: 1.5, finalPrice: 900, serviceIncludes: ['建模', '渲染', '1次小图修改', '4K高清交付'] },
  
  // 卧室
  { spaceType: '卧室', basePrice: 400, styleType: '现代简约', styleMultiplier: 1.0, finalPrice: 400, serviceIncludes: ['建模', '渲染', '1次小图修改'] },
  { spaceType: '卧室', basePrice: 400, styleType: '新中式', styleMultiplier: 1.2, finalPrice: 480, serviceIncludes: ['建模', '渲染', '1次小图修改'] },
  { spaceType: '卧室', basePrice: 400, styleType: '轻奢', styleMultiplier: 1.5, finalPrice: 600, serviceIncludes: ['建模', '渲染', '1次小图修改', '4K高清交付'] },
  
  // 厨房
  { spaceType: '厨房', basePrice: 500, styleType: '现代简约', styleMultiplier: 1.0, finalPrice: 500, serviceIncludes: ['建模', '渲染', '1次小图修改'] },
  { spaceType: '厨房', basePrice: 500, styleType: '新中式', styleMultiplier: 1.2, finalPrice: 600, serviceIncludes: ['建模', '渲染', '1次小图修改'] },
  
  // 别墅
  { spaceType: '别墅', basePrice: 1200, styleType: '现代简约', styleMultiplier: 1.0, finalPrice: 1200, serviceIncludes: ['建模', '渲染', '2次修改', '全景6K交付'] },
  { spaceType: '别墅', basePrice: 1200, styleType: '新中式', styleMultiplier: 1.5, finalPrice: 1800, serviceIncludes: ['建模', '渲染', '2次修改', '全景6K交付', '专属设计师'] }
];