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

export class EventItemDto {
  @ApiProperty({ description: '事件名称', example: 'app_session_start' })
  @IsString()
  eventName: string;

  @ApiPropertyOptional({ description: '用户ID (登录用户)', example: '12345' })
  @IsOptional()
  @IsString()
  userId?: string;

  @ApiProperty({ description: '安装ID', example: 'uuid-xxx-xxx' })
  @IsString()
  installId: string;

  @ApiProperty({ description: '客户端时间戳 (秒)', example: 1732685100 })
  @IsNumber()
  clientTs: number;

  @ApiPropertyOptional({ description: '设备品牌', example: 'Xiaomi' })
  @IsOptional()
  @IsString()
  deviceBrand?: string;

  @ApiPropertyOptional({ description: '设备型号', example: 'Redmi Note 12' })
  @IsOptional()
  @IsString()
  deviceModel?: string;

  @ApiPropertyOptional({ description: '操作系统版本', example: '13' })
  @IsOptional()
  @IsString()
  deviceOs?: string;

  @ApiPropertyOptional({ description: 'App版本号', example: '1.2.0' })
  @IsOptional()
  @IsString()
  appVersion?: string;

  @ApiPropertyOptional({ description: '语言/地区', example: 'zh_CN' })
  @IsOptional()
  @IsString()
  locale?: string;

  @ApiPropertyOptional({ description: '事件专属属性' })
  @IsOptional()
  @IsObject()
  properties?: Record<string, unknown>;
}

export class BatchEventsDto {
  @ApiProperty({ type: [EventItemDto], description: '事件列表' })
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => EventItemDto)
  events: EventItemDto[];
}
