/**
 * 充电桩大盘 - Mock 数据模块
 * 用于本地开发和测试
 */

// 模拟充电站数据
export const MOCK_STATION_DATA = {
  group_id: 'STATION_PLACEHOLDER',
  total_ac: 15,
  free_ac: 3,
  total_dc: 4,
  free_dc: 1,
  fetch_time: new Date().toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit', second: '2-digit' }),
  fetch_timestamp: Date.now(),
  connector_count: 19,
  connectors: [
    // AC 桩 (1-15号)
    { connector_id: 'AC-01', connector_name: '1号枪', type: 'AC', power: 7, state: { type: 'charging', desc: '充电中' }, idle_seconds: 0, charging_seconds: 1800 },
    { connector_id: 'AC-02', connector_name: '2号桩', type: 'AC', power: 7, state: { type: 'free', desc: '空闲' }, idle_seconds: 300, charging_seconds: 0 },
    { connector_id: 'AC-03', connector_name: '3号桩', type: 'AC', power: 7, state: { type: 'charging', desc: '充电中' }, idle_seconds: 0, charging_seconds: 7200 },
    { connector_id: 'AC-04', connector_name: '4号桩', type: 'AC', power: 7, state: { type: 'occupied', desc: '占用' }, idle_seconds: 0, occupied_seconds: 900 },
    { connector_id: 'AC-05', connector_name: '5号桩', type: 'AC', power: 7, state: { type: 'charging', desc: '充电中' }, idle_seconds: 0, charging_seconds: 3600 },
    { connector_id: 'AC-06', connector_name: '6号桩', type: 'AC', power: 7, state: { type: 'free', desc: '空闲' }, idle_seconds: 120, charging_seconds: 0 },
    { connector_id: 'AC-07', connector_name: '7号桩', type: 'AC', power: 7, state: { type: 'charging', desc: '充电中' }, idle_seconds: 0, charging_seconds: 5400 },
    { connector_id: 'AC-08', connector_name: '8号桩', type: 'AC', power: 7, state: { type: 'charging', desc: '充电中' }, idle_seconds: 0, charging_seconds: 1200 },
    { connector_id: 'AC-09', connector_name: '9号桩', type: 'AC', power: 7, state: { type: 'free', desc: '空闲' }, idle_seconds: 60, charging_seconds: 0 },
    { connector_id: 'AC-10', connector_name: '10号枪', type: 'AC', power: 7, state: { type: 'occupied', desc: '占用' }, idle_seconds: 0, occupied_seconds: 3600 },
    { connector_id: 'AC-11', connector_name: '11号桩', type: 'AC', power: 7, state: { type: 'charging', desc: '充电中' }, idle_seconds: 0, charging_seconds: 4800 },
    { connector_id: 'AC-12', connector_name: '12号桩', type: 'AC', power: 7, state: { type: 'charging', desc: '充电中' }, idle_seconds: 0, charging_seconds: 2400 },
    { connector_id: 'AC-13', connector_name: '13号桩', type: 'AC', power: 7, state: { type: 'charging', desc: '充电中' }, idle_seconds: 0, charging_seconds: 90000 }, // 超过1天
    { connector_id: 'AC-14', connector_name: '14号枪', type: 'AC', power: 7, state: { type: 'charging', desc: '充电中' }, idle_seconds: 0, charging_seconds: 1500 },
    { connector_id: 'AC-15', connector_name: '15号枪', type: 'AC', power: 7, state: { type: 'charging', desc: '充电中' }, idle_seconds: 0, charging_seconds: 2100 },
    // AC 桩 - 公牛 (JSF01-JSF03)
    { connector_id: 'AC-JSF01', connector_name: 'Giant内部充电桩（JSF-01）01', type: 'AC', power: 7, state: { type: 'free', desc: '空闲' }, idle_seconds: 300, charging_seconds: 0, vendor: 'gongniu' },
    { connector_id: 'AC-JSF02', connector_name: 'Giant内部充电桩（JSF-02）01', type: 'AC', power: 7, state: { type: 'charging', desc: '充电中' }, idle_seconds: 0, charging_seconds: 3600, vendor: 'gongniu' },
    { connector_id: 'AC-JSF03', connector_name: 'Giant内部充电桩（JSF-03）01', type: 'AC', power: 7, state: { type: 'charging', desc: '充电中' }, idle_seconds: 0, charging_seconds: 1200, vendor: 'gongniu' },
    // DC 桩 - NIO (16-17号)
    { connector_id: 'DC-16', connector_name: '16号枪', type: 'DC', power: 20, state: { type: 'charging', desc: '充电中' }, charging_progress: 65.0, idle_seconds: 0, charging_seconds: 2700, estimated_charging_ready_time: 35, vendor: 'nio' },
    { connector_id: 'DC-17', connector_name: '17号枪', type: 'DC', power: 20, state: { type: 'free', desc: '空闲' }, idle_seconds: 180, charging_seconds: 0, vendor: 'nio' },
    // DC 桩 - 公牛 (18-19号)
    { connector_id: 'DC-18', connector_name: 'Giant内部充电桩（SSL-18）01', type: 'DC', power: 20, state: { type: 'charging', desc: '充电中' }, charging_progress: 42, idle_seconds: 0, charging_seconds: 1800, estimated_charging_ready_time: 45, vendor: 'gongniu' },
    { connector_id: 'DC-19', connector_name: 'Giant内部充电桩（SSL-19）01', type: 'DC', power: 20, state: { type: 'charging', desc: '充电中' }, charging_progress: 24, idle_seconds: 0, charging_seconds: 2400, estimated_charging_ready_time: 60, vendor: 'gongniu' },
  ]
};

/**
 * 模拟 API 响应
 */
export function getMockResponse() {
  // 更新时间
  const now = new Date();
  MOCK_STATION_DATA.fetch_time = now.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
  MOCK_STATION_DATA.fetch_timestamp = Date.now();

  // 随机变化一些状态（模拟真实场景）
  const connectors = MOCK_STATION_DATA.connectors.map(c => {
    // 10% 概率改变状态
    if (Math.random() < 0.1) {
      const states = ['free', 'charging', 'occupied'];
      const newState = states[Math.floor(Math.random() * states.length)];
      return {
        ...c,
        state: { type: newState, desc: newState === 'free' ? '空闲' : newState === 'charging' ? '充电中' : '占用' },
        idle_seconds: newState === 'free' ? Math.floor(Math.random() * 600) : 0,
        charging_seconds: newState === 'charging' ? Math.floor(Math.random() * 7200) : 0,
        occupied_seconds: newState === 'occupied' ? Math.floor(Math.random() * 3600) : 0,
      };
    }
    return c;
  });

  return {
    success: true,
    data: {
      ...MOCK_STATION_DATA,
      connectors,
      // 重新计算统计
      total_ac: connectors.filter(c => c.type === 'AC').length,
      total_dc: connectors.filter(c => c.type === 'DC').length,
      free_ac: connectors.filter(c => c.type === 'AC' && c.state.type === 'free').length,
      free_dc: connectors.filter(c => c.type === 'DC' && c.state.type === 'free').length,
    }
  };
}
