import { IsOptional, IsString, IsDateString, IsInt, Min, Max, IsEnum } from 'class-validator';
import { Type } from 'class-transformer';

export enum PageSortBy {
  VIEWS = 'views',
  UNIQUE_VIEWS = 'unique_views',
  AVG_TIME = 'avg_time',
  BOUNCE_RATE = 'bounce_rate',
  ENGAGEMENT = 'engagement',
}

export enum EventCategory {
  ALL = 'all',
  CLICK = 'click',
  SCROLL = 'scroll',
  FORM = 'form',
  VIDEO = 'video',
  CUSTOM = 'custom',
}

export class EngagementQueryDto {
  @IsDateString()
  startDate!: string;

  @IsDateString()
  endDate!: string;

  @IsOptional()
  @IsString()
  trafficSource?: string;

  @IsOptional()
  @IsString()
  deviceType?: string;

  @IsOptional()
  @IsString()
  country?: string;

  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  @Max(500)
  limit?: number = 20;
}

export class PageQueryDto extends EngagementQueryDto {
  @IsOptional()
  @IsString()
  pathPattern?: string;

  @IsOptional()
  @IsEnum(PageSortBy)
  sortBy?: PageSortBy = PageSortBy.VIEWS;
}

export class EventQueryDto extends EngagementQueryDto {
  @IsOptional()
  @IsEnum(EventCategory)
  category?: EventCategory = EventCategory.ALL;

  @IsOptional()
  @IsString()
  eventType?: string;
}

export class ScrollDepthQueryDto {
  @IsDateString()
  startDate!: string;

  @IsDateString()
  endDate!: string;

  @IsOptional()
  @IsString()
  page?: string;
}

export class UserFlowQueryDto {
  @IsDateString()
  startDate!: string;

  @IsDateString()
  endDate!: string;

  @IsOptional()
  @IsString()
  startPage?: string;

  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(2)
  @Max(10)
  steps?: number = 5;

  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  @Max(50)
  limit?: number = 10;
}

export class NavigationFlowsQueryDto {
  @IsString()
  from!: string;

  @IsDateString()
  startDate!: string;

  @IsDateString()
  endDate!: string;

  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  @Max(50)
  limit?: number = 10;
}
