import type { SeriesOption } from 'echarts';

export enum ActiveType {
  HORIZONTAL = 'horizontal',
  TREND = 'trend',
  TREND_EXTENDED = 'trendExtended',
}

// 定义基础数据类型
export interface StockData {
  o: string; // 开盘价
  c: string; // 收盘价
  h: string; // 最高价
  l: string; // 最低价
  v: string; // 成交量
  d: string; // 日期
  zd: string; // 涨跌幅
  pc?: string; // 涨跌额
}

export interface DateMemo {
  _id: number;
  代码: string;
  日期: string; 
  提示: string;
}

export interface ProcessedData {
  categoryData: string;
  values: {
    value: [string, string, string, string, string];
    itemStyle: {
      color: string;
      borderColor: string;
    }
  };
  volumes: string;
}

export interface SplitData {
  categoryData: string[];
  values: Array<{
    value: number[];
    itemStyle: {
      color: string;
      borderColor: string;  
    }
  }>;
  volumes: [number, string, number][];
}

// 定义图表系列的具体类型
export interface CandlestickSeries {
  name: 'Values';
  type: 'candlestick';
  data: Array<{
    value: number[];
    itemStyle: {
      color: string;
      borderColor: string;
    }
  }>;
}

export interface VolumeSeries {
  name: 'Volumes';
  type: 'bar';
  xAxisIndex: number;
  yAxisIndex: number;
  data: [number, string, number][];
  itemStyle: {
    color: string | ((params: { value: any }) => string);
  };
}

export interface MarkerSeries {
  name: 'SpecificMarkers' | 'DateMemo' | 'Mark';
  type: 'scatter';
  xAxisIndex?: number;
  yAxisIndex?: number;
  data: Array<{
    value: [number, number];
    symbol: string;
    symbolSize: number;
    label: {
      show: boolean;
      formatter: string;
      position: 'top' | 'bottom' | 'left' | 'right';
      color: string;
    };
    itemStyle: {
      color: string;
    };
  }>;
  tooltip: {
    show: boolean;
  };
}

export interface MiddleLineSeries {
  name: 'MiddleLines';
  type: 'lines';
  coordinateSystem: 'cartesian2d';
  data: MiddleLine[];
  lineStyle: {
    color: string;
    width: number;
    type: string;
  };
  effect: {
    show: boolean;
  };
  tooltip: {
    show: boolean;
  };
  z: number;
}

// 图表配置类型
export interface ChartOption {
  series: SeriesOption[];
  [key: string]: any;
  markPoint?: {
    data: TradeMarker[];
    label?: {
      show: boolean;
      position: 'top' | 'bottom';
      formatter: string;
    };
  };
}

// 建议添加这些类型定义
export interface VolumeMarker {
  value: [number, number];
  symbol: string;
  symbolSize: number;
  label: {
    show: boolean;
    formatter: string;
    position: string;
    color: string;
    // ... 其他样式属性
  };
  itemStyle: {
    color: string;
  };
}

export interface MiddleLine {
  coords: [[number, number], [number, number]];
}

// 添加新的类型定义
export interface TradeRecord {
  type: 'BUY' | 'SELL';
  price: number;      // 交易价格（收盘价）
  timestamp: number;
  date: string;
  buyPrice?: number;  // 仅卖出时需要记录买入价
}

// 添加买卖记录数组的类型
export interface TradeRecordGroup {
  date: string;
  type: 'BUY' | 'SELL';
  records: TradeRecord[];
}

// 添加买卖记录的响应类型
export interface TradeResponse {
  success: boolean;
  data?: TradeRecord;
  message?: string;
}

// 修改 MarkerSeries 接口以支持买卖标记
export interface TradeMarker {
  value: [number, number];  // [timestamp, price]
  symbol: 'arrow' | 'arrow-down';  // 买入用上箭头，卖出用下箭头
  symbolSize: number;
  itemStyle: {
    color: string;  // 买入红色，卖出绿色
  };
  label?: {
    show: boolean;
    formatter: string;
    position: 'top' | 'bottom';
    color: string;
  };
}

// 添加收益相关的类型定义
export interface DailyProfit {
  date: string;
  profit: number;  // 当日收益
  trades: TradeRecord[];  // 当日交易记录
}

export interface ProfitSummary {
  totalProfit: number;  // 累计收益
  dailyStats: {  // 当日行情统计
    date: string;  // 添加日期字段
    open: number;
    high: number;
    close: number;
    low: number;
    change: number;  // 日涨幅
  };
}

// 添加训练信息类型定义
export interface TrainingInfo {
  currentProgress: number;
  totalTrainingDays: number;
  remainingDays: number;
  isTrainingComplete: boolean;
  isFixedRangeMode: boolean;
}

export interface UseStockDataFilterReturn {
  filteredData: StockData[];
  moveToNextDay: () => Promise<string>;
  resetTrainingProgress: () => void;
  setDayNum: (days: number) => void;
  initializeView: () => void;
  isInitialized: boolean;
  trainingInfo: TrainingInfo;
  isFixedRangeMode: boolean;
} 