import { TeamInfo } from "@/features/teams/types";
import { Match } from "@/features/matches/types";
import { z } from "zod";

export interface TournamentTeamStats {
  id: string;
  team_id: string;
  tournament_id: string;
  team_name: string;
  matches: number;
  wins: number;
  losses: number;
  total_cups_made: number;
  total_cups_against: number;
  margin_of_victory: number;
  margin_of_loss: number;
  win_percentage: number;
  avg_cups_per_match: number;
}

export interface TournamentInfo {
  id: string;
  name: string;
  location?: string;
  start_time?: string;
  end_time?: string;
  logo?: string;
  glitch_logo?: string;
  first_place?: TeamInfo;
  second_place?: TeamInfo;
  third_place?: TeamInfo;
  regional?: boolean;
}

export interface Tournament {
  id: string;
  name: string;
  location?: string;
  desc?: string;
  rules?: string;
  logo?: string;
  glitch_logo?: string;
  enroll_time?: string;
  start_time: string;
  end_time?: string;
  created: string;
  updated: string;
  teams?: TeamInfo[];
  matches?: Match[];
  first_place?: TeamInfo;
  second_place?: TeamInfo;
  third_place?: TeamInfo;
  team_stats?: TournamentTeamStats[];
  regional?: boolean;
}

export const tournamentInputSchema = z.object({
  name: z.string(),
  location: z.string().optional(),
  desc: z.string().optional(),
  rules: z.string().optional(),
  logo: z.file().optional(),
  enroll_time: z.string(),
  start_time: z.string(),
  end_time: z.string().optional(),
});

export type TournamentInput = z.infer<typeof tournamentInputSchema>;
export type TournamentUpdateInput = Partial<TournamentInput>;
