34 lines
1.3 KiB
PHP
34 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace App\Actions\Ranges;
|
||
|
|
|
||
|
|
use App\Contracts\ActionInput;
|
||
|
|
use Domain\Models\ValueObjects\PictureMetadata;
|
||
|
|
use Illuminate\Http\UploadedFile;
|
||
|
|
use Webmozart\Assert\Assert;
|
||
|
|
|
||
|
|
final readonly class CreateRangeInput implements ActionInput
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
public string $name,
|
||
|
|
public ?string $description,
|
||
|
|
public UploadedFile | string | 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.');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|