import { ApiProperty } from "@nestjs/swagger";
import { Type } from "class-transformer";
import { IsArray, IsIn, IsNumber, IsOptional, ValidateNested } from "class-validator";

export class CommonRelationWhereDto {

    @ApiProperty({description: "Entity da leggere"})
    @IsIn([
        "article",
        "article_barcode",
        "article_category",
        "article_price",
        "article_store",
        "attribute",
        "category",
        "customer",
        "device",
        "operator",
        "payment",
        "price",
        "rate",
        "storage",
        "store",
        "supplier",
        "unit_measure",
        "user",
        "tipology",
        "invoice_counter",
        "credit_note_counter"
    ])
    entity?: string;

    @ApiProperty({description: "Filtro ID"})
    @IsNumber()
    filterIdRelation?: number;

}

export class CommonListDto {

    @ApiProperty({description: "Filtro ID"})
    @IsOptional()
    @IsNumber()
    filterId?: number;

    @ApiProperty({description: "Entity da leggere"})
    @IsIn([
        "article",
        "article_barcode",
        "article_category",
        "article_price",
        "article_store",
        "attribute",
        "category",
        "customer",
        "device",
        "operator",
        "payment",
        "price",
        "rate",
        "storage",
        "store",
        "supplier",
        "unit_measure",
        "user",
        "tipology",
        "invoice_counter",
        "credit_note_counter"
    ])
    entity?: string;

    @ApiProperty({description: "Entity con cui andare in join"})
    @IsIn([
        "article",
        "article_barcode",
        "article_category",
        "article_price",
        "article_store",
        "attribute",
        "category",
        "customer",
        "device",
        "operator",
        "payment",
        "price",
        "rate",
        "storage",
        "store",
        "supplier",
        "unit_measure",
        "user",
        "tipology",
        "invoice_counter",
        "credit_note_counter"
    ], {each: true})
    joins?: string[];

    @ApiProperty({
        description: "Where con filtro ID da parte delle sub entity", 
        type: CommonRelationWhereDto, 
        isArray: true
    })
    @IsArray()
    @ValidateNested({ each: true })
    @Type(() => CommonRelationWhereDto)
    joinsWhere?: CommonRelationWhereDto[];
    
    @ApiProperty({description: "Campia di ordinamento"})
    @IsOptional()
    sortBy?: string;

    @ApiProperty({description: "Lato ordinamento"})
    @IsOptional()
    @IsIn([null, undefined, "DESC", "ASC"])
    sortSide?: "DESC" | "ASC";

}