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

export enum GeoGranularity {
  COUNTRY = 'country',
  REGION = 'region',
  CITY = 'city',
}

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

  @IsDateString()
  endDate!: string;

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

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

export class GeoQueryDto extends AudienceQueryDto {
  @IsOptional()
  @IsEnum(GeoGranularity)
  granularity?: GeoGranularity = GeoGranularity.COUNTRY;

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

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

export class DeviceQueryDto extends AudienceQueryDto {
  @IsOptional()
  @IsString()
  deviceType?: string;
}
