<?php

namespace Opencart\Extension\Alsendo\DTO\Entity;

abstract class AbstractOrderDetailsShipmentEntity
{
    public int $id;
    public int $orderDetailsId;
    public ?int $shippingMethodId;
    public ?string $shippingMethodName;
    public ?int $serviceId;
    public ?string $externalServiceId;
    public ?string $shippingServiceName;
    public ?string $mapOperator;
    public ?string $preferredPickupDate;
    public ?string $preferredPickupHourFrom;
    public ?string $preferredPickupHourTo;
    public ?array $shipmentPickupPoint;
    public ?string $shipmentPickupPointDisplay;

    public static function fromArray(array $data): static
    {
        $self = new static();
        $self->id = (int)$data['id'];
        $self->orderDetailsId = (int)$data['order_details_id'];
        $self->shippingMethodId = isset($data['shipping_method_id']) ? (int)$data['shipping_method_id'] : null;
        $self->shippingMethodName = $data['shipping_method_name'] ?? null;
        $self->serviceId = isset($data['service_id']) ? (int)$data['service_id'] : null;
        $self->externalServiceId = $data['external_service_id'] ?? null;
        $self->shippingServiceName = $data['shipping_service_name'] ?? null;
        $self->mapOperator = $data['map_operator'] ?? null;
        $self->preferredPickupDate = $data['preferred_pickup_date'] ?? null;
        $self->preferredPickupHourFrom = $data['preferred_pickup_hour_from'] ?? null;
        $self->preferredPickupHourTo = $data['preferred_pickup_hour_to'] ?? null;
        $self->shipmentPickupPoint = isset($data['shipment_pickup_point']) ? (is_array($data['shipment_pickup_point']) ? $data['shipment_pickup_point'] : json_decode($data['shipment_pickup_point'], true)) : null;
        $self->shipmentPickupPointDisplay = $data['shipment_pickup_point_display'] ?? null;
        return $self;
    }
}
