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

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

 /**
  * Elasticsearch multi-match query DTO
  */
 @ApiExtraModels()
 export class EsMultimatchQueryDto {
    /**
     * Offset from the start of the list of hits
     */
    @IsOptional()
    @IsInt()
    @ApiPropertyOptional({
        description: 'Offset from the start of the list of hits',
        example: 5,
    })
    public from?: number;

    /**
     * Maximum number of elements returned by Elasticsearch
     */
    @IsOptional()
    @IsInt()
    @ApiPropertyOptional({
        description: 'Maximum number of elements returned by Elasticsearch',
        example: 30
    })
    public size?: number;
    
    /**
     * The search query object passed to Elasticsearch
     */
    @IsDefined()
    @IsObject()
    @ApiProperty({
        description: 'Search query object passed to Elasticsearch',
        example: {
            multi_match: {
                query: 'Maths',
                fields: [
                    'title',
                    'content'
                ]
            }
        },
    })
    private readonly query: Object;

    /**
     * Constructs a multi-match
     */
    constructor(query: string = '', fields: Array<string> = ['content']) {
        this.query = {
            multi_match: {
                query: query,
                fields: fields
            }
        }
    }
 }