ldc-mesbr-app/src/Application/UseCases/Brand/Find/FindBrand.php

45 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Application\UseCases\Brand\Find;
use Application\UseCases\Brand\Find\Output\BrandFound;
use Application\UseCases\Brand\Find\Output\BrandNotFound;
use Application\UseCases\Brand\Find\Output\Output;
use Domain\Models\Entities\Brand;
use Domain\Ports\Repositories\BrandRepository;
use Shared\DDD\UseCases\Input as BaseInput;
use Shared\DDD\UseCases\UseCase;
use Webmozart\Assert\Assert;
/** @implements UseCase<\Application\UseCases\Brand\Find\Input, \Application\UseCases\Brand\Find\Output\Output> */
final readonly class FindBrand implements UseCase
{
public function __construct(
private BrandRepository $repository,
) {
}
#[\Override]
public function execute(BaseInput $input): Output
{
Assert::isInstanceOf($input, Input::class);
$brand = $this->repository->findByCode($input->code);
if (! $brand instanceof Brand) {
return new BrandNotFound();
}
return new BrandFound(
name: $brand->name,
code: $brand->code,
logo: $brand->logo,
rcs: $brand->rcs,
contact: $brand->contact,
createdAt: $brand->createdAt(),
updatedAt: $brand->updatedAt(),
);
}
}