<?php

namespace Opencart\Extension\Alsendo\DTO\Unified;

class SimpleSubmittedOrderPackageDetailsDTO
{
     public ?string $id;
     public ?string $templateName;
     public ?int $width;
     public ?int $height;
     public ?int $length;
     public ?float $weight;
     public ?string $packageType;
     public ?string $pickupType;

    public static function multipleFromOrderShipment(array $orderShipment): array
    {
        $result = [];

        foreach ($orderShipment['packages'] as $package) {
            $dto = new self();

            $dto->id = (string)($package['id'] ?? null);
            $dto->templateName = $package['template_name'] ?? null;
            $dto->width = isset($package['width']) ? (int)$package['width'] : null;
            $dto->height = isset($package['height']) ? (int)$package['height'] : null;
            $dto->length = isset($package['length']) ? (int)$package['length'] : null;
            $dto->weight = isset($package['weight']) ? (float)$package['weight'] : null;
            $dto->packageType = $package['package_type'] ?? null;
            $dto->pickupType = $package['pickup_type'] ?? null;

            $result[] = $dto;
        }

        return $result;
    }

}