import { IsNumber, IsOptional, IsString, IsBoolean, IsArray, ValidateNested, IsIn, Min, MaxLength } from 'class-validator';
import { Type } from 'class-transformer';

export class SaveReceiptItemDto {
  @IsString()
  @MaxLength(191)
  rawName!: string;

  @IsNumber()
  @Min(0)
  quantity!: number;

  @IsString()
  unit!: string;

  @IsOptional()
  @IsNumber()
  price?: number | null;

  @IsOptional()
  @IsString()
  @MaxLength(100)
  brand?: string | null;

  @IsOptional()
  @IsString()
  @MaxLength(100)
  origin?: string | null;

  @IsIn(['inventory', 'pantry'])
  destination!: 'inventory' | 'pantry';

  @IsOptional()
  @IsNumber()
  productId?: number;

  @IsOptional()
  @IsString()
  @MaxLength(191)
  createProductName?: string;

  @IsOptional()
  @IsNumber()
  categoryId?: number | null;

  // Paketfält (kan editeras i UI)
  @IsOptional()
  @IsNumber()
  packQuantity?: number | null;

  @IsOptional()
  @IsString()
  packUnit?: string | null;

  @IsOptional()
  @IsNumber()
  packageCount?: number;

  @IsOptional()
  @IsBoolean()
  learnAlias?: boolean;

  @IsOptional()
  @IsBoolean()
  learnAliasGlobally?: boolean;

  @IsOptional()
  @IsBoolean()
  learnUnitMapping?: boolean;
}

export class SaveReceiptDto {
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => SaveReceiptItemDto)
  items!: SaveReceiptItemDto[];
}
