/**
 * 客户状态管理工具函数
 */

// 客户状态类型定义
export type CustomerStatus = 'all' | 'pending' | 'signed' | 'cancelled';

// 客户状态配置
export const CUSTOMER_STATUS_CONFIG = {
  all: {
    label: '全部',
    color: '#666666',
    tagType: 'default' as const
  },
  pending: {
    label: '跟进中',
    color: '#ff8800',
    tagType: 'warning' as const
  },
  signed: {
    label: '已签约',
    color: '#52c41a',
    tagType: 'success' as const
  },
  cancelled: {
    label: '已取消',
    color: '#999999',
    tagType: 'default' as const
  }
};

/**
 * 获取状态文本
 */
export const getStatusText = (status: CustomerStatus): string => {
  return CUSTOMER_STATUS_CONFIG[status]?.label || '';
};

/**
 * 获取状态标签类型
 */
export const getStatusTagType = (status: CustomerStatus) => {
  return CUSTOMER_STATUS_CONFIG[status]?.tagType || 'default';
};

/**
 * 获取状态颜色
 */
export const getStatusColor = (status: CustomerStatus): string => {
  return CUSTOMER_STATUS_CONFIG[status]?.color || '#666666';
};

/**
 * 获取所有状态选项
 */
export const getStatusOptions = () => {
  return Object.entries(CUSTOMER_STATUS_CONFIG).map(([value, config]) => ({
    value: value as CustomerStatus,
    label: config.label
  }));
};

/**
 * 将数字状态映射为字符串状态
 */
export const mapApplyStatusToCustomerStatus = (applyStatus: number): CustomerStatus => {
  switch (applyStatus) {
    case 10:
      return 'pending';  // 跟进中
    case 20:
      return 'signed';   // 已签约
    case 30:
      return 'cancelled'; // 已取消
    default:
      return 'pending';  // 默认为跟进中
  }
};

/**
 * 将字符串状态映射为数字状态
 */
export const mapCustomerStatusToApplyStatus = (customerStatus: CustomerStatus): number | undefined => {
  switch (customerStatus) {
    case 'pending':
      return 10;  // 跟进中
    case 'signed':
      return 20;  // 已签约
    case 'cancelled':
      return 30;  // 已取消
    case 'all':
      return undefined; // 全部，不筛选
    default:
      return undefined;
  }
};

/**
 * 临时函数：生成随机状态（实际项目中应该删除，从数据库获取真实状态）
 */
export const getRandomStatus = (): CustomerStatus => {
  const statuses: CustomerStatus[] = ['pending', 'signed', 'cancelled'];
  return statuses[Math.floor(Math.random() * statuses.length)];
};
