import { ApiPropertyOptional } from "@nestjs/swagger";
import { Type } from "class-transformer";
import { IsInt, IsOptional, IsString, Max, Min } from "class-validator";

/** Default page size for a thread — roughly two screens of bubbles. */
export const SUPPORT_MESSAGES_DEFAULT_LIMIT = 30;
export const SUPPORT_MESSAGES_MAX_LIMIT = 100;

export class ListMessagesQueryDto {
  @ApiPropertyOptional({
    description:
      "Opaque cursor from a previous response's `nextCursor`. Returns the page " +
      "of messages immediately OLDER than the cursor. Omit for the newest page.",
  })
  @IsOptional()
  @IsString()
  before?: string;

  @ApiPropertyOptional({
    minimum: 1,
    maximum: SUPPORT_MESSAGES_MAX_LIMIT,
    default: SUPPORT_MESSAGES_DEFAULT_LIMIT,
  })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  @Max(SUPPORT_MESSAGES_MAX_LIMIT)
  limit?: number;
}
