import {
  IsString,
  IsInt,
  IsOptional,
  IsBoolean,
  IsNotEmpty,
  MaxLength,
  Min,
  Max,
  IsIn,
  ValidateIf,
} from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';

export class CreateProjectDto {
  @ApiProperty({ example: 3, description: 'Startmonat (1-12)' })
  @IsInt()
  @Min(1)
  @Max(12)
  fromMonth!: number;

  @ApiProperty({ example: 2023, description: 'Startjahr' })
  @IsInt()
  @Min(1970)
  @Max(2100)
  fromYear!: number;

  @ApiProperty({ example: 6, required: false, description: 'Endmonat (1-12)' })
  @IsOptional()
  @ValidateIf((o: CreateProjectDto) => !o.isCurrent)
  @IsInt()
  @Min(1)
  @Max(12)
  toMonth?: number;

  @ApiProperty({ example: 2024, required: false, description: 'Endjahr' })
  @IsOptional()
  @ValidateIf((o: CreateProjectDto) => !o.isCurrent)
  @IsInt()
  @Min(1970)
  @Max(2100)
  toYear?: number;

  @ApiProperty({ example: false, required: false, description: 'Projekt läuft noch' })
  @IsOptional()
  @IsBoolean()
  isCurrent?: boolean;

  @ApiProperty({ example: 'Senior DevOps Engineer' })
  @IsString()
  @IsNotEmpty({ message: 'Tätigkeit ist erforderlich' })
  @MaxLength(200)
  role!: string;

  @ApiProperty({ example: 'Aufbau und Betrieb der Kubernetes-Infrastruktur', required: false })
  @IsOptional()
  @IsString()
  @MaxLength(1500, { message: 'Aufgaben dürfen maximal 1500 Zeichen lang sein' })
  tasks?: string;

  @ApiProperty({ example: 'Xinion GmbH', required: false })
  @IsOptional()
  @IsString()
  @MaxLength(200)
  company?: string;

  @ApiProperty({
    example: '51-200',
    required: false,
    enum: ['1-10', '11-50', '51-200', '201-500', '501-1000', '1001-5000', '5000+'],
  })
  @IsOptional()
  @IsString()
  @IsIn(['1-10', '11-50', '51-200', '201-500', '501-1000', '1001-5000', '5000+'])
  companySize?: string;

  @ApiProperty({ example: 'IT-Dienstleistung', required: false })
  @IsOptional()
  @IsString()
  @MaxLength(200)
  industry?: string;
}
