// Shared types between main and renderer processes

export interface User {
  id: number
  login: string
  nickname: string
  avatar_url?: string
  role: 'USER' | 'ADMIN'
}

export interface TokenResponse {
  access_token: string
  token_type: string
  user: User
}

export interface LoginResponse {
  access_token?: string
  token_type?: string
  user?: User
  requires_2fa?: boolean
  two_factor_session_id?: number
}

// API Response types
export interface MarathonResponse {
  id: number
  title: string
  description?: string
  status: 'preparing' | 'active' | 'finished'
  start_date?: string
  end_date?: string
  cover_url?: string
  is_public: boolean
  participation?: {
    is_organizer: boolean
    points: number
    completed_count: number
    dropped_count: number
  }
}

export interface GameShort {
  id: number
  title: string
  cover_url?: string
  download_url?: string
  game_type?: 'challenges' | 'playthrough'
}

export interface ChallengeResponse {
  id: number
  title: string
  description: string
  type: string
  difficulty: 'easy' | 'medium' | 'hard'
  points: number
  estimated_time?: number
  proof_type: string
  proof_hint?: string
  game: GameShort
  is_generated: boolean
}

export interface PlaythroughInfo {
  description?: string
  points: number
  proof_type: string
  proof_hint?: string
}

export interface AssignmentResponse {
  id: number
  challenge?: ChallengeResponse
  game: GameShort
  is_playthrough: boolean
  playthrough_info?: PlaythroughInfo
  status: 'active' | 'completed' | 'dropped' | 'returned'
  proof_url?: string
  proof_comment?: string
  points_earned: number
  tracked_time_minutes: number
  started_at: string
  completed_at?: string
  can_drop: boolean
  drop_penalty: number
  event_type?: string
}

export interface Marathon {
  id: number
  title: string
  description?: string
  status: 'lobby' | 'active' | 'finished'
  start_date: string
  end_date?: string
  cover_url?: string
}

export interface Game {
  id: number
  name: string
  genre?: string
  cover_url?: string
  marathon_id: number
}

export interface Challenge {
  id: number
  game_id: number
  title: string
  description: string
  type: string
  difficulty: 'easy' | 'medium' | 'hard'
  points: number
  estimated_time: number
  proof_type: string
  proof_hint?: string
}

export interface Assignment {
  id: number
  participant_id: number
  game_id: number
  challenge_id?: number
  game: Game
  challenge?: Challenge
  status: 'active' | 'completed' | 'dropped'
  started_at: string
  completed_at?: string
  time_spent_minutes?: number
}

export interface CurrentChallenge {
  marathon: Marathon
  assignment?: Assignment
}

// Process tracking types
export interface TrackedProcess {
  id: string
  name: string
  displayName: string
  executablePath?: string
  windowTitle?: string
  isGame: boolean
  steamAppId?: string
}

export interface GameSession {
  gameId: string
  gameName: string
  startTime: number
  endTime?: number
  duration: number
  isActive: boolean
}

export interface TrackingStats {
  totalTimeToday: number
  totalTimeWeek: number
  totalTimeMonth: number
  sessions: GameSession[]
  currentGame?: string | null
  currentSessionDuration?: number
}

export interface SteamGame {
  appId: string
  name: string
  installDir: string
  executable?: string
  iconPath?: string
}

export interface TrackedGame {
  id: string
  name: string
  executableName: string
  executablePath?: string
  steamAppId?: string
  iconPath?: string
  totalTime: number
  lastPlayed?: number
}

export interface AppSettings {
  autoLaunch: boolean
  minimizeToTray: boolean
  trackingInterval: number
  apiUrl: string
  theme: 'dark'
}

// IPC Channel types
export interface IpcChannels {
  // Settings
  'get-settings': () => AppSettings
  'save-settings': (settings: Partial<AppSettings>) => void

  // Auth
  'get-token': () => string | null
  'save-token': (token: string) => void
  'clear-token': () => void

  // Process tracking
  'get-running-processes': () => TrackedProcess[]
  'get-foreground-window': () => string | null
  'start-tracking': (processName: string) => void
  'stop-tracking': () => void
  'get-tracking-stats': () => TrackingStats

  // Steam
  'get-steam-games': () => SteamGame[]
  'get-steam-path': () => string | null

  // Tracked games
  'get-tracked-games': () => TrackedGame[]
  'add-tracked-game': (game: Omit<TrackedGame, 'totalTime' | 'lastPlayed'>) => TrackedGame
  'remove-tracked-game': (gameId: string) => void
  'update-game-time': (gameId: string, time: number) => void

  // Window
  'minimize-to-tray': () => void
  'quit-app': () => void
}
