// 模拟数据

// 期货品种列表
export const futuresList = [
  // 金属类
  { code: 'AU', name: '黄金', type: '金属', exchange: 'SHFE' },
  { code: 'AG', name: '白银', type: '金属', exchange: 'SHFE' },
  { code: 'CU', name: '铜', type: '金属', exchange: 'SHFE' },
  { code: 'NI', name: '镍', type: '金属', exchange: 'SHFE' },
  { code: 'SN', name: '锡', type: '金属', exchange: 'SHFE' },
  { code: 'AL', name: '铝', type: '金属', exchange: 'SHFE' },
  { code: 'ZN', name: '锌', type: '金属', exchange: 'SHFE' },
  { code: 'PB', name: '铅', type: '金属', exchange: 'SHFE' },
  
  // 建材类
  { code: 'FG', name: '玻璃', type: '建材', exchange: 'CZCE' },
  { code: 'LY', name: '烧碱', type: '建材', exchange: 'CZCE' },
  { code: 'SA', name: '纯碱', type: '建材', exchange: 'CZCE' },
  { code: 'JM', name: '焦煤', type: '建材', exchange: 'DCE' },
  { code: 'RB', name: '螺纹钢', type: '建材', exchange: 'SHFE' },
  { code: 'ALO', name: '氧化铝', type: '建材', exchange: 'SHFE' },
  { code: 'HC', name: '热轧卷板', type: '建材', exchange: 'SHFE' },
  
  // 能源化工类
  { code: 'MA', name: '甲醇', type: '能源化工', exchange: 'CZCE' },
  { code: 'V', name: 'PVC', type: '能源化工', exchange: 'DCE' },
  { code: 'FU', name: '燃油', type: '能源化工', exchange: 'SHFE' },
  { code: 'SC', name: '原油', type: '能源化工', exchange: 'INE' },
  { code: 'RU', name: '橡胶', type: '能源化工', exchange: 'SHFE' },
  { code: 'BR', name: '合成橡胶', type: '能源化工', exchange: 'DCE' },
  { code: 'NR', name: '20号胶', type: '能源化工', exchange: 'SHFE' },
  { code: 'BU', name: '沥青', type: '能源化工', exchange: 'SHFE' },
  { code: 'LU', name: '低硫燃油', type: '能源化工', exchange: 'INE' },
  { code: 'L', name: '聚乙烯', type: '能源化工', exchange: 'DCE' },
  { code: 'PP', name: '聚丙烯', type: '能源化工', exchange: 'DCE' },
  { code: 'TA', name: 'PTA', type: '能源化工', exchange: 'CZCE' },
  
  // 农产品类
  { code: 'P', name: '棕榈油', type: '农产品', exchange: 'DCE' },
  { code: 'A', name: '大豆', type: '农产品', exchange: 'DCE' },
  { code: 'B', name: '豆粕', type: '农产品', exchange: 'DCE' },
  { code: 'M', name: '豆粕', type: '农产品', exchange: 'DCE' },
  { code: 'Y', name: '豆油', type: '农产品', exchange: 'DCE' },
  { code: 'C', name: '玉米', type: '农产品', exchange: 'DCE' },
  { code: 'CS', name: '玉米淀粉', type: '农产品', exchange: 'DCE' },
  { code: 'CF', name: '棉花', type: '农产品', exchange: 'CZCE' },
  { code: 'SR', name: '白糖', type: '农产品', exchange: 'CZCE' },
  { code: 'RM', name: '菜籽粕', type: '农产品', exchange: 'CZCE' },
  { code: 'OI', name: '菜籽油', type: '农产品', exchange: 'CZCE' },
  
  // 新能源类
  { code: 'LI', name: '碳酸锂', type: '新能源', exchange: 'SHFE' },
  { code: 'SI', name: '工业硅', type: '新能源', exchange: 'GEM' },
  { code: 'SP', name: '多晶硅', type: '新能源', exchange: 'GEM' },
  
  // 金融类
  { code: 'IM', name: '中证1000', type: '金融', exchange: 'CFFEX' },
  { code: 'IC', name: '中证500', type: '金融', exchange: 'CFFEX' },
  { code: 'IH', name: '上证50', type: '金融', exchange: 'CFFEX' },
  
  // 其他
  { code: 'I', name: '铁矿石', type: '其他', exchange: 'DCE' },
  { code: 'J', name: '焦炭', type: '其他', exchange: 'DCE' },
  { code: 'ZC', name: '动力煤', type: '其他', exchange: 'CZCE' }
];

// 生成随机数据的工具函数
const generateRandomPrice = (base, volatility) => {
  return +(base + (Math.random() - 0.5) * 2 * volatility).toFixed(2);
};

const generateRandomChange = () => {
  return +(Math.random() * 10 - 5).toFixed(2);
};

const generateRandomWinRate = () => {
  return Math.floor(Math.random() * 50) + 30;
};

const generateRandomATR = () => {
  return +(Math.random() * 5 + 0.5).toFixed(2);
};

const generateRandomADX = () => {
  return Math.floor(Math.random() * 60) + 10;
};

const getADXStatus = (adx) => {
  if (adx < 20) return '无趋势/震荡';
  if (adx < 40) return '弱趋势';
  return '强趋势';
};

const getTrendDirection = () => {
  const directions = ['看多', '看空', '观望'];
  return directions[Math.floor(Math.random() * directions.length)];
};

const getTrendStatus = (direction) => {
  if (direction === '看多') return '多头趋势';
  if (direction === '看空') return '空头趋势';
  return '震荡';
};

const generateRandomRSI = () => {
  return Math.floor(Math.random() * 80) + 10;
};

// 生成品种详细数据
export const generateFutureData = (code, name) => {
  const currentPrice = generateRandomPrice(2000, 500);
  const changePercent = generateRandomChange();
  const atr = generateRandomATR();
  const adx = generateRandomADX();
  const winRate = generateRandomWinRate();
  
  const trends = {
    '5MIN': {
      direction: getTrendDirection(),
      status: getTrendStatus(getTrendDirection()),
      rsi: generateRandomRSI()
    },
    '30MIN': {
      direction: getTrendDirection(),
      status: getTrendStatus(getTrendDirection()),
      rsi: generateRandomRSI()
    },
    '1HOUR': {
      direction: getTrendDirection(),
      status: getTrendStatus(getTrendDirection()),
      rsi: generateRandomRSI()
    },
    '1DAY': {
      direction: getTrendDirection(),
      status: getTrendStatus(getTrendDirection()),
      rsi: generateRandomRSI()
    }
  };
  
  const indicators = {
    macd: ['金叉向上', '死叉向下', '走平'][Math.floor(Math.random() * 3)],
    rsi: `${generateRandomRSI()}(中性)`,
    bollinger: ['触及上轨', '触及下轨', '中轨附近'][Math.floor(Math.random() * 3)],
    kdj: ['金叉向上', '死叉向下', '走平'][Math.floor(Math.random() * 3)]
  };
  
  const entry = currentPrice;
  const stopLoss = entry * (1 - 0.02 * (Math.random() + 0.5));
  const target = entry * (1 + 0.03 * (Math.random() + 0.5));
  const resistance = entry * (1 + 0.05 * (Math.random() + 0.5));
  const support = entry * (1 - 0.05 * (Math.random() + 0.5));
  
  const overallViews = ['观望', '中线', '多头排列', '空头排列', '震荡'];
  const overallView = overallViews[Math.floor(Math.random() * overallViews.length)];
  
  return {
    code,
    name,
    fullName: `${name}-${code}605`,
    currentPrice,
    changePercent,
    atr,
    adx,
    adxStatus: getADXStatus(adx),
    winRate,
    trends,
    indicators,
    tradingAdvice: {
      entry: +entry.toFixed(2),
      stopLoss: +stopLoss.toFixed(2),
      target: +target.toFixed(2),
      resistance: +resistance.toFixed(2),
      support: +support.toFixed(2)
    },
    riskLevel: ['低', '中等', '高'][Math.floor(Math.random() * 3)],
    volatility: ['低', '中等', '高'][Math.floor(Math.random() * 3)],
    overallView,
    aiAnalysis: `MACD:${indicators.macd} | RSI:${indicators.rsi} | 布林带:${indicators.bollinger}`
  };
};

// 生成多个品种的概览数据
export const generateFuturesOverview = () => {
  return futuresList.map(item => {
    const data = generateFutureData(item.code, item.name);
    return {
      code: data.code,
      name: data.name,
      currentPrice: data.currentPrice,
      changePercent: data.changePercent,
      winRate: data.winRate,
      atr: data.atr,
      adx: data.adx,
      adxStatus: data.adxStatus,
      trends: data.trends,
      tradingAdvice: data.tradingAdvice,
      overallView: data.overallView,
      aiAnalysis: data.aiAnalysis
    };
  });
};

// 风险预警数据
export const riskAlerts = [
  { id: 1, title: '原油波动加剧', level: '高', message: '原油价格近期波动较大，建议控制仓位' },
  { id: 2, title: '螺纹钢换月提醒', level: '中等', message: '螺纹钢主力合约即将换月，请注意移仓' },
  { id: 3, title: '市场情绪偏空', level: '中等', message: '多数品种技术指标显示空头信号，建议谨慎操作' },
  { id: 4, title: '铜库存下降', level: '低', message: '铜库存持续下降，可能影响价格走势' }
];

// AI市场研判
export const aiMarketAnalysis = {
  overallTrend: '震荡偏弱',
  keyFactors: ['原油价格波动', '宏观经济数据', '政策面变化'],
  recommendations: ['控制仓位', '关注原油走势', '做好止损'],
  confidence: 75
};

// K线图模拟数据
export const generateKlineData = (days = 30) => {
  const data = [];
  let price = 2000;
  
  for (let i = 0; i < days; i++) {
    const open = price;
    const high = open + Math.random() * 50;
    const low = open - Math.random() * 50;
    const close = low + Math.random() * (high - low);
    const volume = Math.floor(Math.random() * 100000) + 10000;
    
    data.push({
      time: new Date(Date.now() - (days - i) * 24 * 60 * 60 * 1000).getTime() / 1000,
      open: +open.toFixed(2),
      high: +high.toFixed(2),
      low: +low.toFixed(2),
      close: +close.toFixed(2),
      volume
    });
    
    price = close;
  }
  
  return data;
};