<?php

namespace App\Mapper;

use App\ApiResource\EventApi;
use App\ApiResource\ZoneApi;
use App\Entity\Event;
use Symfonycasts\MicroMapper\AsMapper;
use Symfonycasts\MicroMapper\MapperInterface;

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

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

        return $dto;
    }

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

        $dto->dbId = $entity->getId();
        $dto->name = $entity->getName();
        $dto->identifier = $entity->getIdentifier();
        $dto->sequence = $entity->getSequence();
        $dto->mandatory = $entity->isMandatory();
        $dto->createdAt = $entity->getCreatedAt();

        return $dto;
    }
}