/**
 * CRM 线索管理模块类型定义
 * API契约参考：docs/crm-api-contract-v3.md
 */

/**
 * 线索视图对象（响应）
 */
export interface CrmLeadVo {
  leadId: number;
  tenantId: string;
  customerCode?: string; // ERP客户编码
  companyName: string;
  contactName: string;
  mobile: string;
  wechat?: string;
  province?: string;
  city?: string;
  regionId?: number;
  regionName?: string;
  sourceType?: string;
  sourceTypeName?: string;
  activityName?: string;
  referrerName?: string;
  industry?: string;
  industryName?: string;
  companyScale?: string;
  storeCount?: number;
  intentLevel?: string;
  intentLevelName?: string;
  aiScore?: number;
  riskLevel?: string;
  riskLevelName?: string;
  ownerUserId?: number;
  ownerUserName?: string;
  leadStatus: string;
  leadStatusName?: string;
  convertedDealerId?: number;
  nextFollowTime?: string;
  remark?: string;
  createBy: number;
  createByName?: string;
  createTime: string;
  updateBy?: number;
  updateByName?: string;
  updateTime?: string;
}

/**
 * 线索业务对象（请求）
 */
export interface CrmLeadBo {
  leadId?: number;
  customerCode?: string; // ERP客户编码（可选）
  companyName: string;
  contactName: string;
  mobile: string;
  wechat?: string;
  province?: string;
  city?: string;
  regionId?: number;
  sourceType?: string;
  activityName?: string;
  referrerName?: string;
  industry?: string;
  companyScale?: string;
  storeCount?: number;
  ownerUserId?: number;
  remark?: string;
}

/**
 * 线索查询参数
 */
export interface LeadQueryParams {
  companyName?: string; // 公司名称（模糊查询）
  mobile?: string; // 手机号
  intentLevel?: string; // AI意向等级
  riskLevel?: string; // 风险等级
  ownerUserId?: number; // 负责人ID
  leadStatus?: string; // 线索状态
  sourceType?: string; // 来源类型
  customerCode?: string; // ERP客户编码
  pageNum: number;
  pageSize: number;
}

/**
 * 线索跟进记录视图对象
 */
export interface CrmLeadFollowVo {
  followId: number;
  leadId: number;
  followType: string;
  followTypeName?: string;
  content: string;
  aiSummary?: string;
  nextFollowTime?: string;
  followUserId: number;
  followUserName?: string;
  createTime: string;
}

/**
 * 线索跟进记录业务对象
 */
export interface CrmLeadFollowBo {
  followId?: number;
  leadId: number;
  followType: string;
  content: string;
  nextFollowTime?: string;
}

/**
 * 线索分配请求
 */
export interface LeadAssignRequest {
  leadId: number;
  ownerUserId: number; // 新负责人ID
}

/**
 * 线索转经销商请求（第二阶段）
 */
export interface LeadConvertRequest {
  leadId: number;
  dealerName: string;
  dealerCode: string;
  customerCode?: string; // ERP客户编码（可选）
  signedAt?: string; // 签约时间
  level?: string; // 经销商等级 (A/B/C)
}

/**
 * ========================================
 * CRM 商机管理模块类型定义
 * ========================================
 */

/**
 * 商机视图对象（响应）
 */
export interface CrmOpportunityVo {
  opportunityId: number;
  tenantId: string;
  dealerId: number;
  dealerName?: string; // 经销商名称（翻译）
  opportunityName: string;
  stage: string;
  stageName?: string; // 阶段名称（翻译）
  amount?: number; // 商机金额
  probability?: number; // 成功概率（百分比）
  expectedCloseDate?: string; // 预计成交日期
  actualCloseDate?: string; // 实际成交日期
  ownerUserId?: number;
  ownerUserName?: string; // 负责人姓名（翻译）
  productName?: string;
  description?: string;
  sourceLeadId?: number; // 来源线索ID
  status: string;
  statusName?: string; // 状态名称（翻译）
  createBy: number;
  createByName?: string;
  createTime: string;
  updateBy?: number;
  updateByName?: string;
  updateTime?: string;
}

/**
 * 商机业务对象（请求）
 */
export interface CrmOpportunityBo {
  opportunityId?: number;
  dealerId: number; // 经销商ID（必填）
  opportunityName: string; // 商机名称（必填）
  stage?: string; // 商机阶段
  amount?: number; // 商机金额
  probability?: number; // 成功概率（0-100）
  expectedCloseDate?: string; // 预计成交日期
  actualCloseDate?: string; // 实际成交日期
  ownerUserId?: number; // 负责人
  productName?: string;
  description?: string;
  sourceLeadId?: number; // 来源线索ID
  status?: string; // 状态
}

/**
 * 商机查询参数
 */
export interface OpportunityQueryParams {
  dealerId?: number; // 经销商ID
  opportunityName?: string; // 商机名称（模糊查询）
  stage?: string; // 商机阶段
  ownerUserId?: number; // 负责人ID
  status?: string; // 状态
  pageNum: number;
  pageSize: number;
}

/**
 * 通用响应格式 R<T>
 */
export interface R<T> {
  code: number;
  msg: string;
  data?: T;
}

/**
 * 分页响应格式 TableDataInfo<T>
 */
export interface TableDataInfo<T> {
  code: number;
  msg: string;
  rows: T[];
  total: number;
}