import { Type } from 'class-transformer';
import { ArrayMaxSize, IsArray, IsEnum, IsInt, IsMongoId, IsNumber, IsOptional, IsString, Max, MaxLength, Min, ValidateNested } from 'class-validator';
import { EngagementEventType } from '../engagement-event-type.enum';

export class TrackEngagementDto {
  @IsMongoId()
  postId!: string;

  @IsEnum(EngagementEventType)
  type!: EngagementEventType;

  @IsOptional()
  @IsInt()
  @Min(0)
  @Max(7_200_000)
  watchTimeMs?: number;

  @IsOptional()
  @IsNumber()
  @Min(0)
  @Max(100)
  progressPercent?: number;

  @IsOptional()
  @IsString()
  @MaxLength(100)
  sessionId?: string;
}

export class TrackEngagementBatchDto {
  @IsArray()
  @ArrayMaxSize(50)
  @ValidateNested({ each: true })
  @Type(() => TrackEngagementDto)
  events!: TrackEngagementDto[];
}
