import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsNumber, IsOptional } from 'class-validator';

import { PagingDefault } from '../../constants';

export class ChatPagingQuery {
  @ApiPropertyOptional({ description: 'Offset', example: 0 })
  @IsOptional()
  @IsNumber()
  offset?: number;

  @ApiPropertyOptional({ description: 'Limit', example: 10 })
  @IsOptional()
  @IsNumber()
  limit?: number;

  @ApiPropertyOptional({ description: 'Cursor position for pagination' })
  @IsOptional()
  @IsNumber()
  cursor?: number;

  constructor(offset: number | undefined, limit: number | undefined, cursor: number | undefined) {
    this.offset = offset;
    this.limit = limit;
    this.cursor = cursor;
  }

  static default(): ChatPagingQuery {
    return new ChatPagingQuery(undefined, undefined, undefined);
  }

  get skip(): number {
    return this.offset ?? PagingDefault.offset;
  }

  get take(): number {
    return this.limit ?? PagingDefault.limit;
  }
}
