ldc-cocotte/app/Actions/Products/CreateProductInput.php

56 lines
1.7 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace App\Actions\Products;
use App\Contracts\ActionInput;
use Carbon\CarbonInterface;
use Domain\Enums\ProductBrand;
use Domain\Enums\SellUnit;
use Domain\Enums\TaxRate;
use Domain\Enums\Units\InvoicingUnit;
use Domain\Enums\Units\OrderUnit;
use Money\Money;
use Webmozart\Assert\Assert;
final readonly class CreateProductInput implements ActionInput
{
/**
* @param array<array{id?: int|string, label: string}> $tags
* @param list<string> $associatedProductsIds
*/
public function __construct(
public string $name,
public string $shortDescription,
public string $description,
public Money $price,
public InvoicingUnit $invoicingUnit,
public int $stock,
public int $rangeId,
public SellUnit $sellUnit,
public OrderUnit $orderUnit,
public TaxRate $taxRate,
public ProductBrand $brand,
public ?int $weight = null,
public bool $weightVariable = false,
public ?CarbonInterface $orderableStart = null,
public ?CarbonInterface $orderableEnd = null,
public bool $star = false,
public bool $status = false,
public mixed $picture = null,
public ?string $pictureAlt = null,
public ?string $pictureTitle = null,
public mixed $pictureLarge = null,
public ?string $pictureLargeAlt = null,
public ?string $pictureLargeTitle = null,
public array $tags = [],
public array $associatedProductsIds = [],
) {
Assert::stringNotEmpty(trim($this->name));
Assert::maxLength($this->name, 255);
Assert::greaterThanEq($this->stock, 0);
Assert::greaterThanEq($this->rangeId, 1);
}
}