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

export interface PlayerInfo {
  id: string;
  first_name?: string;
  last_name?: string;
}

export interface Player {
  id: string;
  auth_id?: string;
  first_name?: string;
  last_name?: string;
  created?: string;
  updated?: string;
  last_activity?: string;
  teams?: TeamInfo[];
}

export const playerInputSchema = z.object({
  auth_id: z.string().optional(),
  first_name: z.string().min(2).max(20).regex(/^[a-zA-Z0-9\s]+$/, "First name must be 2-20 characters long and contain only letters and spaces"),
  last_name: z.string().min(2).max(20).regex(/^[a-zA-Z0-9\s]+$/, "Last name must be 2-20 characters long and contain only letters and spaces"),
});

export const playerUpdateSchema = playerInputSchema.extend({
  last_activity: z.string().optional(),
}).partial();

export type PlayerInput = z.infer<typeof playerInputSchema>;
export type PlayerUpdateInput = z.infer<typeof playerUpdateSchema>;

export interface PlayerStats {
  id: string;
  player_id: string;
  player_name: string;
  matches: number;
  tournaments: number;
  wins: number;
  losses: number;
  total_cups_made: number;
  total_cups_against: number;
  win_percentage: number;
  avg_cups_per_match: number;
  margin_of_victory: number;
  margin_of_loss: number;
}
