<?php

namespace App\Mapper;

use App\ApiResource\ZoneApi;
use App\Entity\Zone;
use Symfonycasts\MicroMapper\AsMapper;
use Symfonycasts\MicroMapper\MapperInterface;

#[AsMapper(from: Zone::class, to: ZoneApi::class)]
class ZoneEntityToApiMapper implements MapperInterface
{
    public function load(object $from, string $toClass, array $context): object
    {
        $entity = $from;
        assert($entity instanceof Zone);

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

        return $dto;
    }

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

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

        return $dto;
    }
}