*/ final readonly class CreateBrand implements UseCase, Transactional { public function __construct( private BrandRepository $repository, private PictureStorage $pictureStorage, ) { } #[\Override] public function execute(BaseInput $input): Output { Assert::isInstanceOf($input, Input::class); if ($this->repository->existsByCode($input->code)) { throw new \DomainException(sprintf('Brand code "%s" already exists.', $input->code->value)); } $logoPath = $this->pictureStorage->store($input->logo); $brand = Brand::create( code: $input->code, name: $input->name, logo: $logoPath, rcs: $input->rcs, contact: $input->contact, ); $this->repository->save($brand); return new Output( name: $brand->name, code: $brand->code, logo: $brand->logo, rcs: $brand->rcs, contact: $brand->contact, ); } }