import { ApiExtraModels, ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { IsDefined, IsNotEmpty, IsOptional } from "class-validator";
import { EsQueryDto } from "./elastic/es-query.dto";
import { SearchQueryDto } from "./search-q.dto";

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

/**
 * Request object, which contains query parameters and Elasticsearch query object
 */
@ApiExtraModels()
export class RequestDto {
    /**
     * Query parameters object
     */
    @IsDefined()
    @IsNotEmpty()
    @ApiProperty({
        type: SearchQueryDto,
        description: 'Actual query with parameters acquired from the request',
        example: {}
    })
    query: SearchQueryDto;
    
    /**
     * Elasticsearch query object
     */
    @IsOptional()
    @ApiPropertyOptional({
        type: EsQueryDto,
        description: 'Elasticsearch query body constructed by pagination mechanism',
        example: {},
    })
    es_query?: EsQueryDto;

     /**
      * Constructs an object with provided parameters
      * @param query
      * @param es_query
      */
    constructor(query: SearchQueryDto, es_query: EsQueryDto) {
        this.query = query;
        this.es_query = es_query;
    }
}