import { IsBoolean, IsNotEmpty, IsOptional, IsString, Matches, MaxLength } from 'class-validator';

export class CreateDeviceDto {
  @IsString()
  @IsNotEmpty()
  @MaxLength(120)
  name: string;

  // Must match the broker username (or future TLS cert CN) the device connects with
  @IsString()
  @Matches(/^[a-zA-Z0-9._-]{3,64}$/, {
    message: 'mqttUsername must be 3-64 chars of letters, digits, dot, dash, underscore',
  })
  mqttUsername: string;

  @IsOptional()
  @IsString()
  @MaxLength(120)
  serialNumber?: string;
}

export class UpdateDeviceDto {
  @IsOptional()
  @IsString()
  @IsNotEmpty()
  @MaxLength(120)
  name?: string;

  @IsOptional()
  @IsString()
  @MaxLength(120)
  serialNumber?: string;

  @IsOptional()
  @IsBoolean()
  isActive?: boolean;
}
