import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
  IsString,
  IsInt,
  IsOptional,
  IsBoolean,
  IsArray,
  ValidateNested,
  Min,
  Max,
  IsEnum,
} from 'class-validator';
import { Type } from 'class-transformer';
import { S3Type } from '@prisma/client';

/**
 * DTO for creating a new S3 category within a plan
 */
export class CreateS3CategoryDto {
  @ApiProperty({
    description: 'Category name',
    example: 'Werkzeugablage',
    minLength: 2,
    maxLength: 100,
  })
  @IsString()
  name: string;

  @ApiProperty({
    description: 'S3 Type (SEIRI, SEITON, SEISO)',
    enum: S3Type,
    example: S3Type.SEIRI,
  })
  @IsEnum(S3Type)
  s3Type: S3Type;

  @ApiPropertyOptional({
    description: 'Sort order for display',
    example: 0,
    default: 0,
  })
  @IsOptional()
  @IsInt()
  @Min(0)
  sortOrder?: number;
}

/**
 * DTO for creating a new S3 plan
 */
export class CreateS3PlanDto {
  @ApiProperty({
    description: 'Department ID',
    example: 'clq1234567890abcdef',
  })
  @IsString()
  departmentId: string;

  @ApiProperty({
    description: 'Year of the plan',
    example: 2024,
    minimum: 2020,
    maximum: 2100,
  })
  @IsInt()
  @Min(2020)
  @Max(2100)
  year: number;

  @ApiProperty({
    description: 'Month of the plan (1-12)',
    example: 1,
    minimum: 1,
    maximum: 12,
  })
  @IsInt()
  @Min(1)
  @Max(12)
  month: number;

  @ApiPropertyOptional({
    description: 'Whether the plan is active',
    example: true,
    default: true,
  })
  @IsOptional()
  @IsBoolean()
  isActive?: boolean;

  @ApiPropertyOptional({
    description: 'Initial categories to create with the plan',
    type: [CreateS3CategoryDto],
  })
  @IsOptional()
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => CreateS3CategoryDto)
  categories?: CreateS3CategoryDto[];
}

/**
 * DTO for adding a category to an existing plan
 */
export class AddS3CategoryDto extends CreateS3CategoryDto {
  // Inherits all properties from CreateS3CategoryDto
}
