ldc-cocotte/app/Cqs/Actions/Ranges/UpdateRangeInput.php

36 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Cqs\Actions\Ranges;
use App\Contracts\ActionInput;
use App\Models\Range;
use Domain\Models\ValueObjects\PictureMetadata;
use Illuminate\Http\UploadedFile;
use Uwil\Storage\Lib\ValueObjects\StorageFilePath;
use Webmozart\Assert\Assert;
final readonly class UpdateRangeInput implements ActionInput
{
public function __construct(
public Range $range,
public string $name,
public ?string $description,
public UploadedFile | StorageFilePath | null $picture,
public PictureMetadata $pictureMetadata,
public bool $status,
) {
$trimmedName = trim($this->name);
Assert::stringNotEmpty($trimmedName, 'The range name cannot be empty.');
Assert::minLength($trimmedName, 2, 'The range name must be at least 2 characters.');
Assert::maxLength($trimmedName, 45, 'The range name cannot exceed 45 characters.');
if ($this->picture !== null) {
Assert::notNull($this->pictureMetadata->alt, 'Picture alt is required when picture is provided.');
Assert::stringNotEmpty(trim($this->pictureMetadata->alt), 'Picture alt cannot be empty when picture is provided.');
Assert::notNull($this->pictureMetadata->title, 'Picture title is required when picture is provided.');
Assert::stringNotEmpty(trim($this->pictureMetadata->title), 'Picture title cannot be empty when picture is provided.');
}
}
}