import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsInt, Min, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { Transform, Type } from 'class-transformer';
import { AssemblyMonitoringBaseQueryDto } from './base.query.dto';

export class AssemblyMonitoringUnitDetailQueryDto extends AssemblyMonitoringBaseQueryDto {
  @ApiProperty({ type: Number })
  @IsNotEmpty()
  @Type(() => Number)
  @IsInt()
  @Min(0)
  modelSeq!: number;

  @ApiProperty({ type: Number })
  @IsNotEmpty()
  @Type(() => Number)
  @IsInt()
  @Min(0)
  prodPlanSeq!: number;

  @ApiProperty({ type: String })
  @IsNotEmpty()
  @Transform(({ value }) =>
    typeof value === 'string' ? value.trim() : String(value).trim(),
  )
  @IsString()
  serialNo!: string;

  @ApiPropertyOptional({ type: Number })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(0)
  specSeq?: number;

  @ApiPropertyOptional({ type: String })
  @IsOptional()
  @Transform(({ value }) =>
    typeof value === 'string' ? value.trim() : String(value).trim(),
  )
  @IsString()
  workingEndDate?: string;
}

export type AssemblyMonitoringUnitDetailQueryWithDefaults =
  AssemblyMonitoringUnitDetailQueryDto & {
    factUnit: number;
    specSeq: number;
    workingEndDate: string;
  };
