<?php

namespace Opencart\Extension\Alsendo\DTO;

class OrderPreferredPickupRequestDTO
{
    public ?string $hourFrom = null;
    public ?string $hourTo = null;
    public ?string $date = null;

    public static function tryCreateFromPayload(array $payload): ?self
    {
        if (!array_key_exists('shipment_preferred_pickup_hour_from', $payload)) {
            return null;
        }

        if (!array_key_exists('shipment_preferred_pickup_hour_to', $payload)) {
            return null;
        }

        if (!array_key_exists('shipment_preferred_pickup_date', $payload)) {
            return null;
        }

        $dto = new self();

        $dto->hourFrom = $payload['shipment_preferred_pickup_hour_from'];
        $dto->hourTo = $payload['shipment_preferred_pickup_hour_to'];
        $dto->date = $payload['shipment_preferred_pickup_date'];

        return $dto;
    }
} 