// Go models/ 구조체와 1:1 대응하는 TypeScript 타입 정의

export interface StockPrice {
  code: string
  name: string
  currentPrice: number
  changePrice: number
  changeRate: number
  volume: number
  tradeMoney: number
  high: number
  low: number
  open: number
  tradeTime: string
  tradeVolume: number
  askPrice1: number
  bidPrice1: number
  marketStatus: string
  cntrStr: number
  market: string
  updatedAt: string
}

export interface CandleData {
  time: number
  open: number
  high: number
  low: number
  close: number
  volume: number
}

export interface StockInfo {
  code: string
  name: string
  market: string
}

export interface OrderBookEntry {
  price: number
  volume: number
}

export interface OrderBook {
  code: string
  askTime: string
  asks: OrderBookEntry[]
  bids: OrderBookEntry[]
  totalAskVol: number
  totalBidVol: number
  expectedPrc: number
  expectedVol: number
}

export interface ThemeGroup {
  code: string
  name: string
  stockCount: number
  fluSig: string
  fluRt: number
  risingCount: number
  fallCount: number
  periodRt: number
  mainStock: string
}

export interface ThemeStock {
  code: string
  name: string
  curPrc: number
  fluSig: string
  predPre: number
  fluRt: number
}

export interface ThemeDetail {
  fluRt: number
  periodRt: number
  stocks: ThemeStock[]
}

export interface Kospi200Stock {
  code: string
  name: string
  curPrc: number
  predPreSig: string
  predPre: number
  fluRt: number
  volume: number
  open: number
  high: number
  low: number
}

export interface AutoTradeRule {
  id: string
  name: string
  enabled: boolean
  minRiseScore: number
  minCntrStr: number
  requireBullish: boolean
  orderAmount: number
  maxPositions: number
  stopLoss1Pct: number
  stopLoss1Count: number
  stopLossPct: number
  takeProfitPct: number
  maxHoldMinutes: number
  exitBeforeClose: boolean
  createdAt: string
}

export interface AutoTradePosition {
  code: string
  name: string
  buyPrice: number
  qty: number
  orderNo: string
  entryTime: string
  ruleId: string
  stopLoss1: number
  stopLoss1Touches: number
  stopLoss: number
  takeProfit: number
  status: string
  exitTime?: string
  exitPrice?: number
  exitReason?: string
}

export interface AutoTradeLog {
  at: string
  level: string
  message: string
  code: string
}

export interface AutoTradeStatus {
  running: boolean
  activePositions: number
  tradeCount: number
  totalPL: number
}

export interface WatchlistItem {
  code: string
  name: string
}

export interface IndexQuote {
  name: string
  value: number
  change: number
  changeRate: number
}

// SignalStock — scanner_service.go의 SignalStock과 1:1 대응
export interface Signal {
  // StockPrice 임베드 필드
  code: string
  name: string
  currentPrice: number
  changePrice: number
  changeRate: number
  volume: number
  high: number
  low: number
  open: number
  cntrStr: number
  market: string
  // 시그널 전용 필드
  prevCntrStr: number
  risingCount: number
  detectedAt: string
  sentiment: string        // 호재/악재/중립/정보없음
  sentimentReason: string
  targetPrice: number
  targetReason: string
  riseScore: number
  riseLabel: string        // "매우 높음" | "높음" | ""
  nextDayTrend: string     // 상승 | 하락 | 횡보
  nextDayConf: string      // 높음 | 보통 | 낮음
  nextDayReason: string
  // 복합 지표
  totalAskVol: number
  totalBidVol: number
  askBidRatio: number
  volDelta: number
  volRatio: number
  upperWick: number
  pricePos: number
  signalType: string       // 강한매수 | 매수우세 | 물량소화 | 추격위험 | 약한상승
}

export interface NewsItem {
  title: string
  url: string
  publishedAt: string
  source: string
}

export interface Disclosure {
  rceptNo: string
  corpName: string
  reportNm: string
  rceptDt: string
  flrNm: string
  url: string
  tag: string
}

export interface AccountBalance {
  totalAsset: number
  deposit: number
  stockValue: number
  profitLoss: number
  profitRate: number
  stocks: BalanceStock[]
}

export interface BalanceStock {
  code: string
  name: string
  qty: number
  buyPrice: number
  curPrice: number
  profitLoss: number
  profitRate: number
  value: number
}

// 미체결 주문 항목
export interface PendingOrder {
  ordNo: string    // 주문번호
  stkCd: string    // 종목코드
  stkNm: string    // 종목명
  ordQty: string   // 주문수량
  ordPric: string  // 주문가격
  osoQty: string   // 미체결수량
  ioTpNm: string   // 주문구분
  trdeTp: string   // 매매구분 (1:매도, 2:매수)
  tm: string       // 시간
  cntrPric: string // 체결가
  cntrQty: string  // 체결량
}

// 체결내역 항목
export interface OrderHistory {
  ordNo: string
  stkNm: string
  ioTpNm: string
  ordPric: string
  ordQty: string
  cntrPric: string
  cntrQty: string
  osoQty: string
  trdeCmsn: string
  trdeTax: string
  ordStt: string
  trdeTp: string
  ordTm: string
  stkCd: string
}

export interface OrderRequest {
  code: string
  qty: number
  price: number
  tradeType?: string
  exchange?: string
}

export interface OrderResult {
  orderNo: string
  code: string
  qty: number
  price: number
}

export interface ThemeRef {
  code: string
  name: string
}

export interface AutoTradeWatchSource {
  useScanner: boolean
  selectedThemes: ThemeRef[]
}
