<?php

namespace Opencart\Extension\Alsendo\DTO\Entity;

require_once(DIR_EXTENSION . 'alsendo/src/DTO/Entity/AlsendoRegionEntity.php');
require_once(DIR_EXTENSION . 'alsendo/src/DTO/Entity/AbstractOrderDetailsSenderEntity.php');
require_once(DIR_EXTENSION . 'alsendo/src/DTO/Entity/AbstractOrderDetailsShippingAddressEntity.php');
require_once(DIR_EXTENSION . 'alsendo/src/DTO/Entity/AbstractOrderDetailsPackageDetailsEntity.php');
require_once(DIR_EXTENSION . 'alsendo/src/DTO/Entity/AbstractOrderDetailsShipmentEntity.php');

use Opencart\Extension\Alsendo\DTO\Entity\AlsendoRegionEntity;

abstract class OrderDetailsEntity
{
    public int $id;
    public ?AlsendoRegionEntity $region;
    public int $orderId;
    public \DateTimeImmutable $createdAt;
    public ?\DateTimeImmutable $updatedAt;
    public ?AbstractOrderDetailsSenderEntity $sender;
    public ?AbstractOrderDetailsShippingAddressEntity $shippingAddress;
    public ?AbstractOrderDetailsPackageDetailsEntity $packageDetails;
    public ?AbstractOrderDetailsShipmentEntity $shipment;

    public static function fromArray(array $data): static
    {
        $dto = new static();
        $dto->id = (int)$data['id'];
        $dto->orderId = (int)$data['order_id'];
        $dto->createdAt = new \DateTimeImmutable($data['created_at']);
        $dto->updatedAt = !empty($data['updated_at']) ? new \DateTimeImmutable($data['updated_at']) : null;
        return $dto;
    }
}
