import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  IsInt,
  IsOptional,
  IsString,
  Matches,
  Max,
  MaxLength,
  Min,
  MinLength,
  ValidateNested,
} from 'class-validator';
import { RegrasDto } from './regras.dto';

export class CriarPoolDto {
  @ApiProperty({ example: 'Bolão do setor' })
  @IsString()
  @MinLength(3, { message: 'dê um nome ao bolão' })
  @MaxLength(60)
  name!: string;

  @ApiProperty({
    example: 'BSA',
    description: 'só Brasileirão Série A nesta versão',
  })
  @IsString()
  @Matches(/^[A-Z]{2,4}$/, { message: 'código de campeonato inválido' })
  competitionCode!: string;

  @ApiProperty({ example: 23, minimum: 1, maximum: 38 })
  @IsInt()
  @Min(1)
  @Max(38)
  matchdayFrom!: number;

  @ApiProperty({ example: 38, minimum: 1, maximum: 38 })
  @IsInt()
  @Min(1)
  @Max(38)
  matchdayTo!: number;

  @ApiPropertyOptional({
    type: RegrasDto,
    description: 'omitido usa o padrão do PRD: 10 / 5 / 3',
  })
  @IsOptional()
  @ValidateNested()
  @Type(() => RegrasDto)
  rules?: RegrasDto;
}

export class JogoResponse {
  @ApiProperty() id!: string;
  @ApiProperty() matchday!: number;
  @ApiProperty() homeTeam!: string;
  @ApiProperty() awayTeam!: string;
  @ApiProperty() kickoffAt!: Date;
  @ApiProperty() status!: string;
}

export class PoolResponse {
  @ApiProperty() id!: string;
  @ApiProperty() name!: string;
  @ApiProperty() competitionCode!: string;
  @ApiProperty() matchdayFrom!: number;
  @ApiProperty() matchdayTo!: number;
  @ApiProperty({ description: 'quantos jogos entraram no bolão' })
  totalMatches!: number;

  @ApiProperty({
    description:
      'quantos desses jogos ainda têm prazo aberto. Zero = ninguém vai ' +
      'conseguir palpitar neste bolão, e o app precisa avisar',
  })
  openMatches!: number;
  @ApiProperty() createdAt!: Date;
}
