<?php
namespace App\Mapper;

use App\ApiResource\ShippingCompanyApi;
use App\Entity\ShippingCompany;
use App\Entity\Vessel;
use Symfonycasts\MicroMapper\AsMapper;
use Symfonycasts\MicroMapper\MapperInterface;
use Symfonycasts\MicroMapper\MicroMapperInterface;

#[AsMapper(from: ShippingCompany::class, to: ShippingCompanyApi::class)]
class ShippingCompanyEntityToApiMapper implements MapperInterface
{
    public function __construct(
        private MicroMapperInterface $microMapper
    ) {
    }

    public function load(object $from, string $toClass, array $context): object
    {
        $entity = $from;
        assert($entity instanceof ShippingCompany);

        $dto = new ShippingCompanyApi();
        $dto->id = $entity->getId();

        return $dto;
    }

    public function populate(object $from, object $to, array $context): object
    {
        $entity = $from;
        $dto = $to;
        assert($entity instanceof ShippingCompany);
        assert($dto instanceof ShippingCompanyApi);

        $dto->dbId = $entity->getId();
        $dto->name = $entity->getName();
        $dto->code = $entity->getCode();
        $dto->createdAt = $entity->getCreatedAt();

        return $dto;
    }
}