import { ApiExtraModels, ApiProperty } from "@nestjs/swagger";
import { IsDefined, IsInt, IsNotEmpty, IsOptional, IsString } from "class-validator";

/**
 * List of allowed properties in this DTO
 */
const allowedProperties = ['query', 'pagen', 'limit', 'order'];

/**
 * Elasticsearch response DTO
 */
@ApiExtraModels()
export class SearchQueryDto {
    /**
     * Given query string to perform the
     * search on.
     */
    @IsDefined()
    @IsNotEmpty()
    @IsString()
    @ApiProperty({
        description: 'query',
        example: 'Particle Accelerator'
    })
    query: string;
    
    /**
     * Page number to display.
     */
    @IsDefined()
    @IsNotEmpty()
    @IsInt()
    @ApiProperty({
        description: 'page',
        example: 3,
    })
    page: number;

    /**
     * Limits the number of displayed elements.
     */
    @IsOptional()
    @IsInt()
    @ApiProperty({
        description: 'limit',
        example: 10,
    })
    limit: number;

    /**
     * Limits the number of displayed elements.
     */
     @IsOptional()
     @IsString()
     @ApiProperty({
         description: 'order',
         example: 'asc',
     })
     order: string;

     /**
      * Constructs an object with provided parameters
      * @param query 
      * @param page 
      * @param limit 
      * @param order 
      */
     constructor(query: string, page: number, limit: number, order: string) {
        this.query = query;
        this.page = page;
        this.limit = limit;
        this.order = order;
     }
}