import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsString, IsOptional, IsObject, ValidateNested } from 'class-validator';
import { ClientDeviceDto } from './client-device.dto';
import { AttributionDto } from './attribution.dto';

/**
 * Page view tracking DTO
 */
export class TrackViewDto {
  @ApiProperty({ description: 'Full URL of the page being viewed' })
  @IsString()
  pageUrl!: string;

  @ApiProperty({ description: 'Referrer URL', required: false })
  @IsOptional()
  @IsString()
  referrer?: string;

  @ApiProperty({ description: 'User ID if authenticated', required: false })
  @IsOptional()
  @IsString()
  userId?: string;

  @ApiProperty({ description: 'Session ID from client' })
  @IsString()
  sessionId!: string;

  @ApiProperty({ description: 'Additional metadata', required: false })
  @IsOptional()
  @IsObject()
  metadata?: Record<string, unknown>;

  @ApiProperty({
    description: 'Client-side device data from navigator APIs',
    type: ClientDeviceDto,
    required: false,
  })
  @IsOptional()
  @ValidateNested()
  @Type(() => ClientDeviceDto)
  clientDevice?: ClientDeviceDto;

  @ApiProperty({
    description: 'UTM attribution parameters (first-touch)',
    type: AttributionDto,
    required: false,
  })
  @IsOptional()
  @ValidateNested()
  @Type(() => AttributionDto)
  attribution?: AttributionDto;
}
