ldc-boutique-cnc-sable/domain/Models/ValueObjects/OrderLineProduct.php
2026-10-27 09:58:12 +01:00

47 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Domain\Models\ValueObjects;
use Domain\Enums\ProductBrand;
use Domain\Enums\TaxRate;
use Domain\Enums\Units\OrderUnit;
use Domain\Models\ValueObjects\Entities\ProductId;
use Money\Money;
final readonly class OrderLineProduct
{
public function __construct(
public IncoId $incoId,
public ProductId $originalId,
public string $name,
public ProductWeight $weight,
public ProductBrand $brand,
public OrderUnit $orderUnit,
public Money $price,
public Money $discountedPrice,
public Money $priceKgTtc,
public TaxRate $taxRate,
public ?string $picture = null
) {
if (trim($name) === '') {
throw new \DomainException('Product name cannot be empty');
}
if ($price->isNegative()) {
throw new \DomainException('Product price cannot be negative');
}
if ($discountedPrice->isNegative()) {
throw new \DomainException('Product discounted price cannot be negative');
}
if ($priceKgTtc->isNegative()) {
throw new \DomainException('Price per kg TTC cannot be negative');
}
if ($discountedPrice->greaterThan($price)) {
throw new \DomainException('Product discounted price cannot be greater than original price');
}
if (! $priceKgTtc->isPositive()) {
throw new \DomainException('Price per kg TTC has to be positive');
}
}
}