<?php

namespace Opencart\Extension\Alsendo\OrderDetails\Zaslat;

require_once(DIR_EXTENSION . 'alsendo/src/OrderDetails/CreateOrderDetails.php');
require_once(DIR_EXTENSION . 'alsendo/src/DTO/Entity/AlsendoRegionEntity.php');

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

class ZaslatCreateOrderDetails extends CreateOrderDetails
{
    protected function preparePackageDataForInsert(array $packageData, AlsendoRegionEntity $currentRegion): array
    {
        $packageData = parent::preparePackageDataForInsert($packageData, $currentRegion);
        if (isset($packageData['cod_value']) && $packageData['cod_value'] !== '' && $packageData['cod_value'] !== null && (float)$packageData['cod_value'] > 0) {
            $packageData['cod_value'] = (float)round((float)$packageData['cod_value']);
        }
        return $packageData;
    }
}
