import { ApiProperty } from '@nestjs/swagger';
import { IsIn, IsNotEmpty, IsOptional, Validate } from 'class-validator';
import { IsNotExist } from 'src/utils/validators/is-not-exists.validator';
import { CarType } from '../entities/car.entity';

export class CreateCarDto {
  @ApiProperty({ required: true })
  @IsNotEmpty()
  userId: string;

  @ApiProperty({ required: true })
  @IsNotEmpty()
  makerBrandId: number;

  @ApiProperty({ required: false })
  @IsOptional()
  vinCode?: string;

  @ApiProperty({ required: false })
  @IsOptional()
  engineCode?: string;

  @ApiProperty({ required: true })
  @IsNotEmpty()
  @Validate(IsNotExist, ['CarEntity'], {
    message: 'با این پلاک، قبلا یک خودرو، ثبت شده است',
  })
  number: string;

  @ApiProperty({ required: true, enum: CarType })
  @IsNotEmpty()
  @IsIn(Object.values(CarType))
  type: CarType;
}
