<?php

namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\Modificator;

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldValueModificator;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\DataProvider\DropshippingDataProvider;
use WC_Product;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Form\Fields\ExportMapperFormFields;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Factory\ModificatorFactory;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldFloatValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldCustomFloatValueModificator;
class PriceProductFieldModificator implements ProductFieldValueModificator, ProductFieldFloatValue, ProductFieldCustomFloatValueModificator
{
    private DropshippingDataProvider $data_provider;
    private ModificatorFactory $modificator_factory;
    private WC_Product $product;
    private ?float $value = null;
    public function __construct(ModificatorFactory $modificator_factory, DropshippingDataProvider $data_provider)
    {
        $this->modificator_factory = $modificator_factory;
        $this->data_provider = $data_provider;
    }
    public function set_product(WC_Product $product): void
    {
        $this->product = $product;
    }
    public function set_float_value(float $value): void
    {
        $this->value = $value;
    }
    public function has_float_value(): bool
    {
        return \is_float($this->get_float_value());
    }
    public function get_float_value(): ?float
    {
        if (!\is_float($this->value)) {
            return null;
        }
        $raw_conditions = $this->data_provider->get(ExportMapperFormFields::PRODUCT_ADVANCED_PRICE_MOD);
        $modificator_collection = $this->modificator_factory->create_modificator_collection($raw_conditions);
        $value = $modificator_collection->get_value($this->product, $this->value);
        return \is_numeric($value) ? (float) $value : null;
    }
}
