// 推送服务

import { logger } from '../utils/logger';

// 模拟推送设置存储
const pushSettings: Record<string, any> = {
  'AU': {
    methods: ['email', 'wechat'],
    timing: 'realTime',
    content: ['price', 'trend', 'risk'],
    price_level: 300
  },
  'AG': {
    methods: ['email'],
    timing: 'realTime',
    content: ['price', 'trend'],
    price_level: 50
  }
};

// 模拟推送历史存储
const pushHistory: any[] = [
  { id: 1, timestamp: new Date().toISOString(), method: 'email', content: 'AU价格突破3000', status: 'success' },
  { id: 2, timestamp: new Date().toISOString(), method: 'wechat', content: 'AG趋势改变', status: 'success' },
  { id: 3, timestamp: new Date().toISOString(), method: 'email', content: 'CU风险预警', status: 'failed' }
];

// 获取推送设置
export const fetchPushSettings = async (symbol: string) => {
  // 模拟API请求延迟
  await new Promise(resolve => setTimeout(resolve, 200));
  
  return pushSettings[symbol] || {
    methods: ['email'],
    timing: 'realTime',
    content: ['price']
  };
};

// 保存推送设置
export const savePushSettings = async (symbol: string, settings: any) => {
  // 模拟API请求延迟
  await new Promise(resolve => setTimeout(resolve, 300));
  
  pushSettings[symbol] = settings;
  logger.log(`保存推送设置: ${symbol} ${JSON.stringify(settings)}`);
  
  return settings;
};

// 测试推送
export const testPush = async (method: string, content: string) => {
  // 模拟API请求延迟
  await new Promise(resolve => setTimeout(resolve, 500));
  
  logger.log(`测试推送: ${method} ${content}`);
  
  // 模拟推送成功
  return { success: true, message: '测试推送成功' };
};

// 获取推送历史
export const fetchPushHistory = async () => {
  // 模拟API请求延迟
  await new Promise(resolve => setTimeout(resolve, 200));
  
  return pushHistory;
};