import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsArray, IsNumber, IsOptional, IsString, ValidateNested } from 'class-validator';

export class LeagueCapacityAndScoringSocialLinksDTO {
  @ApiProperty({ required: false, nullable: true })
  @IsOptional()
  @IsString()
  discordUrl?: string;

  @ApiProperty({ required: false, nullable: true })
  @IsOptional()
  @IsString()
  youtubeUrl?: string;

  @ApiProperty({ required: false, nullable: true })
  @IsOptional()
  @IsString()
  websiteUrl?: string;
}

export class LeagueCapacityAndScoringSettingsDTO {
  @ApiProperty()
  @IsNumber()
  maxDrivers!: number;

  @ApiProperty({ required: false, nullable: true })
  @IsOptional()
  @IsNumber()
  sessionDuration?: number;

  @ApiProperty({ required: false, nullable: true })
  @IsOptional()
  @IsString()
  qualifyingFormat?: string;
}

export class LeagueCapacityAndScoringSummaryScoringDTO {
  @ApiProperty()
  @IsString()
  gameId!: string;

  @ApiProperty()
  @IsString()
  gameName!: string;

  @ApiProperty()
  @IsString()
  primaryChampionshipType!: 'driver' | 'team' | 'nations' | 'trophy';

  @ApiProperty()
  @IsString()
  scoringPresetId!: string;

  @ApiProperty()
  @IsString()
  scoringPresetName!: string;

  @ApiProperty()
  @IsString()
  dropPolicySummary!: string;

  @ApiProperty()
  @IsString()
  scoringPatternSummary!: string;
}

export class LeagueWithCapacityAndScoringDTO {
  @ApiProperty()
  @IsString()
  id!: string;

  @ApiProperty()
  @IsString()
  name!: string;

  @ApiProperty()
  @IsString()
  description!: string;

  @ApiProperty()
  @IsString()
  ownerId!: string;

  @ApiProperty()
  @IsString()
  createdAt!: string;

  @ApiProperty({ type: LeagueCapacityAndScoringSettingsDTO })
  @ValidateNested()
  @Type(() => LeagueCapacityAndScoringSettingsDTO)
  settings!: LeagueCapacityAndScoringSettingsDTO;

  @ApiProperty()
  @IsNumber()
  usedSlots!: number;

  @ApiProperty({ required: false, nullable: true })
  @IsOptional()
  @IsString()
  category?: string;

  @ApiProperty({ required: false, nullable: true, type: LeagueCapacityAndScoringSocialLinksDTO })
  @IsOptional()
  @ValidateNested()
  @Type(() => LeagueCapacityAndScoringSocialLinksDTO)
  socialLinks?: LeagueCapacityAndScoringSocialLinksDTO;

  @ApiProperty({ required: false, nullable: true, type: LeagueCapacityAndScoringSummaryScoringDTO })
  @IsOptional()
  @ValidateNested()
  @Type(() => LeagueCapacityAndScoringSummaryScoringDTO)
  scoring?: LeagueCapacityAndScoringSummaryScoringDTO;

  @ApiProperty({ required: false, nullable: true })
  @IsOptional()
  @IsString()
  timingSummary?: string;

  @ApiProperty({ required: false, nullable: true })
  @IsOptional()
  @IsString()
  logoUrl?: string | null;

  @ApiProperty({ required: false })
  @IsOptional()
  @IsNumber()
  pendingJoinRequestsCount?: number;

  @ApiProperty({ required: false })
  @IsOptional()
  @IsNumber()
  pendingProtestsCount?: number;

  @ApiProperty({ required: false })
  @IsOptional()
  @IsNumber()
  walletBalance?: number;
}

export class AllLeaguesWithCapacityAndScoringDTO {
  @ApiProperty({ type: [LeagueWithCapacityAndScoringDTO] })
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => LeagueWithCapacityAndScoringDTO)
  leagues!: LeagueWithCapacityAndScoringDTO[];

  @ApiProperty()
  @IsNumber()
  totalCount!: number;
}