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

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

  // Broker username (or future TLS cert CN) if this device connects to MQTT
  // itself; locators relayed by a gateway need only a serial number.
  @IsOptional()
  @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(64)
  serialNumber?: string;
}

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

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

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