export interface Game {
  steam_app_id: number
  name: string
  path: string
}

export interface SteamCollection {
  id: number
  steam_id: string
  title: string
  description: string
  author_name: string
  total_items: number
  unique_visitors: number
  current_favorites: number
  accepting_submissions: boolean
  created_at: string
  updated_at: string
}

export interface PointsFactor {
  cost: number
  cycles: number
  area: number
}

export interface SteamCollectionItem {
  id: number
  steam_item_id: string
  title: string
  author_name: string
  description: string
  tags?: string[]
  order_index?: number
  steam_url: string
  points_factor?: PointsFactor
  created_at: string
  updated_at: string
}

export interface OpusMagnumData {
  puzzle: string
  cost: number
  cycles: number
  area: number
  confidence: {
    puzzle: number
    cost: number
    cycles: number
    area: number
    overall: number
  }
}

export interface SubmissionFile {
  file: File
  file_url: string
  preview: string
  type: 'image' | 'gif'
  ocrData?: OpusMagnumData
  ocrProcessing?: boolean
  ocrError?: string
  original_filename?: string
  manualPuzzleSelection?: string
  needsManualPuzzleSelection?: boolean
}

export interface PuzzleResponse {
  id?: number
  // puzzle: number | SteamCollectionItem
  puzzle_id: number
  puzzle_name: string
  cost?: number
  cycles?: number
  area?: number
  needs_manual_validation?: boolean
  ocr_confidence_cost?: number
  ocr_confidence_cycles?: number
  ocr_confidence_area?: number
  validated_cost?: number
  validated_cycles?: number
  validated_area?: number
  final_cost?: number
  final_cycles?: number
  final_area?: number
  files?: SubmissionFile[]
  created_at?: string
  updated_at?: string
}

export interface Submission {
  id?: string
  user?: number | null
  responses: PuzzleResponse[]
  notes?: string
  is_validated?: boolean
  validated_by?: number | null
  validated_at?: string | null
  manual_validation_requested?: boolean
  total_responses?: number
  needs_validation?: boolean
  created_at?: string
  updated_at?: string
}

export interface UserInfo {
  id?: number
  username?: string
  first_name?: string
  last_name?: string
  email?: string
  is_authenticated: boolean
  is_staff: boolean
  is_superuser: boolean
  cas_groups?: string[]
}

export interface WinnerFile {
  file_url: string
  original_filename: string
}

export interface WinnerResponse {
  user_id: number
  username: string
  final_cost?: number
  final_cycles?: number
  final_area?: number
  rank_points?: number
  total_coef?: number
  files: WinnerFile[]
}

export interface PuzzleSubmissions {
  puzzle_id: number
  puzzle_title: string
  submissions: WinnerResponse[]
}

export interface TournamentSubmissions {
  submissions: PuzzleSubmissions[]
}

export interface PuzzlePointsFactor {
  cost: number
  cycles: number
  area: number
}

export interface PuzzleSubmissionWithRank {
  rank: number
  user_id: number
  username: string
  final_cost?: number
  final_cycles?: number
  final_area?: number
  rank_points?: number
  total_coef?: number
  files: WinnerFile[]
}

export interface PuzzleResults {
  puzzle_id: number
  puzzle_title: string
  points_factor?: PuzzlePointsFactor
  submissions: PuzzleSubmissionWithRank[]
}

export interface TournamentPuzzleResults {
  results: PuzzleResults[]
}

export interface MarketOption {
  uuid: string
  text: string
  position: number
}

export interface Market {
  uuid: string
  title: string
  description: string
  type: 'yes_no' | 'multiple'
  status: 'open' | 'closed' | 'resolved'
  end_date: string
  created_at: string
  options: MarketOption[]
  winning_option?: MarketOption | null
  userHasBet?: boolean
}

export interface UserBet {
  uuid: string
  amount: number
  created_at: string
  option: MarketOption
  market: Market
}
