/// <reference types="vite/client" />

import type { AppSettings, TrackedProcess, SteamGame, TrackedGame, TrackingStats, User, LoginResponse } from '@shared/types'

interface ApiResult<T> {
  success: boolean
  data?: T
  error?: string
  status?: number
}

declare global {
  interface Window {
    electronAPI: {
      // Settings
      getSettings: () => Promise<AppSettings>
      saveSettings: (settings: Partial<AppSettings>) => Promise<void>

      // Auth (local storage)
      getToken: () => Promise<string | null>
      saveToken: (token: string) => Promise<void>
      clearToken: () => Promise<void>

      // API calls (through main process - no CORS)
      apiLogin: (login: string, password: string) => Promise<ApiResult<LoginResponse>>
      api2faVerify: (sessionId: number, code: string) => Promise<ApiResult<LoginResponse>>
      apiGetMe: () => Promise<ApiResult<User>>
      apiRequest: <T>(method: string, endpoint: string, data?: unknown) => Promise<ApiResult<T>>

      // Process tracking
      getRunningProcesses: () => Promise<TrackedProcess[]>
      getForegroundWindow: () => Promise<string | null>
      getTrackingStats: () => Promise<TrackingStats>

      // Steam
      getSteamGames: () => Promise<SteamGame[]>
      getSteamPath: () => Promise<string | null>

      // Tracked games
      getTrackedGames: () => Promise<TrackedGame[]>
      addTrackedGame: (game: Omit<TrackedGame, 'totalTime' | 'lastPlayed'>) => Promise<TrackedGame>
      removeTrackedGame: (gameId: string) => Promise<void>

      // Window controls
      minimizeToTray: () => void
      quitApp: () => void

      // Events
      onTrackingUpdate: (callback: (stats: TrackingStats) => void) => () => void
      onGameStarted: (callback: (gameName: string) => void) => () => void
      onGameStopped: (callback: (gameName: string, duration: number) => void) => () => void
    }
  }
}
