<?php

declare(strict_types=1);

namespace KupShop\BalikonosBundle\BalikobotAdapters;

class BalikobotRabenAdapter implements IBalikobotAdapter
{
    public function transformOrderData(\Order $order, array $data, array &$custom_data): array
    {
        // Je nutné zasílat buďto atribut volume nebo atributy width, length a height.
        $rParams = $order->getPurchaseState()->getDeliveryRestrictionParams();
        if (($volume = $rParams->getMaxVolume()) && ($maxDimensions = $rParams->getMaxDimensions())) {
            $data['volume'] = $volume / 1000; // liters to m3
            $data['width'] = reset($maxDimensions);
            $data['length'] = next($maxDimensions);
            $data['height'] = next($maxDimensions);
        } elseif (isset($data['width'], $data['length'], $data['height'])) {
            // cm3 to m3
            $data['volume'] = ($data['width'] * $data['length'] * $data['height']) / 1000000;
        }

        $data['content'] = $this->getItemsContentDescription();
        $data['loading_length_pallets'] = 1;
        $data['mu_type'] = 'ep';

        return $data;
    }

    public function getItemsContentDescription(): string
    {
        return 'Zboží';
    }
}
