<?php

declare(strict_types=1);

namespace External\PompoBundle\Overrides\Feed;

use KupShop\I18nBundle\Entity\Currency;

class ProductWrapper extends \KupShop\FeedsBundle\Wrapper\ProductWrapper
{
    /** Nákupní cena bez korekce kurzu (bez DPH).
     *
     * @module PRODUCTS__PRICE_BUY
     */
    public function field_pompo_price_buy(): float
    {
        /** @var Currency $currency */
        $currency = $this->object['price_buy']['currency_object'];

        $rateWithCorrection = $rateWithoutCorrection = $currency->getRate();
        if (!$currency->getCorrections()->isZero()) {
            $rateWithoutCorrection = $rateWithCorrection->sub($currency->getCorrections());
        }

        $priceBuy = toDecimal($this->object['price_buy']['value_without_vat'] ?? 0);
        $priceBuy = $priceBuy->mul($rateWithCorrection)->div($rateWithoutCorrection);

        return $priceBuy->asFloat();
    }
}
