import {
  IsString,
  IsOptional,
  IsNumber,
  IsUUID,
  IsObject,
  MaxLength,
  ValidateNested,
  ArrayMaxSize,
} from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

export class TelemetryEventItem {
  @ApiProperty({ example: 'page_view', maxLength: 64 }) @IsString() @MaxLength(64) eventName: string;
  @ApiProperty({ example: 'inst_abc123', maxLength: 128 }) @IsString() @MaxLength(128) installId: string;
  @ApiPropertyOptional() @IsOptional() @IsUUID() userId?: string;
  @ApiProperty({ example: 1700000000000 }) @IsNumber() clientTs: number;
  @ApiPropertyOptional({ type: 'object' }) @IsOptional() @IsObject() properties?: Record<string, any>;
}

export class BatchEventsDto {
  @ApiProperty({ type: [TelemetryEventItem] })
  @ValidateNested({ each: true })
  @Type(() => TelemetryEventItem)
  @ArrayMaxSize(500)
  events: TelemetryEventItem[];
}
