import { ApiProperty } from "@nestjs/swagger";
import { IsIn, IsOptional, Max } from "class-validator";

export class ArticleBarcodeDto {

    @ApiProperty({description: "Codice barcode"})
    barcode?: string;

    @ApiProperty({description: "Ratio di conversione rispetto unità di misura principale"})
    ratio?: number;

}

export class ArticlePriceDto {

    @ApiProperty({description: "Prezzo lordo articolo"})
    price?: number;

    @ApiProperty({description: "Prezzo imponibile articolo"})
    taxable?: number;

    @ApiProperty({description: "Listino prezzi"})
    idPriceList?: number;

    @ApiProperty({description: "ID aliquota"})
    @IsOptional()
    idRate?: number | null | undefined;

}

export class ArticleImageDto {

    @ApiProperty({description: "Link al media"})
    link?: string;

    @ApiProperty({description: "Da passare caso in cui sia un media locale"})
    @IsOptional()
    idMedia?: number | null | undefined;

    @ApiProperty({description: "Se copertina in POS"})
    @IsOptional()
    coverPos?: number;

}

export class ArticleCreateDto {

    @ApiProperty({description: "ID in caso di aggiornamento"})
    @IsOptional()
    id?: number;

    @ApiProperty({description: "Codice articolo"})
    @Max(100)
    code?: string;

    @ApiProperty({description: "Titolo articolo"})
    @Max(100)
    title?: string;

    @ApiProperty({description: "Sottotitolo articolo"})
    @Max(100)
    @IsOptional()
    subtitle?: string;

    @ApiProperty({description: "Descrizione breve articolo"})
    @Max(200)
    @IsOptional()
    shortDescription?: string;

    @ApiProperty({description: "Descrizione lunga articolo"})
    @Max(200)
    @IsOptional()
    longDescription?: string;

    @ApiProperty({description: "Composizione articolo"})
    @IsOptional()
    attribute?: string;

    @ApiProperty({description: "SKU articolo"})
    @IsOptional()
    sku?: string;

    @ApiProperty({description: "Sconto percentuale"})
    @IsOptional()
    discount?: number;

    @ApiProperty({description: "Disponibile sul POS per la vendita"})
    @IsIn([0, 1])
    @IsOptional()
    availableOnPos?: number;

    @ApiProperty({description: "ID unità misura principale"})
    idUnitMeasure?: number;

    @ApiProperty({description: "ID aliquota"})
    idRate?: number;

    @ApiProperty({description: "ID categorie", isArray: true})
    idCategories?: number[];

    @ApiProperty({description: "ID punti vendita", isArray: true})
    idStores?: number[];

    @ApiProperty({description: "Barcodes", type: ArticleBarcodeDto, isArray: true})
    barcodes?: ArticleBarcodeDto[];

    @ApiProperty({description: "Prezzi", type: ArticlePriceDto, isArray: true})
    prices?: ArticlePriceDto[];

    @ApiProperty({description: "Immagini", type: ArticleImageDto, isArray: true})
    images?: ArticleImageDto[];

}