<?php

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

use WC_Product;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\AvailModificator;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldStringValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldValueModificator;
class AvailProductFieldValue implements ProductFieldValue, ProductFieldStringValue, AvailModificator
{
    public const KEY = 'avail';
    private ?string $value = null;
    private WC_Product $product;
    private ?ProductFieldValueModificator $modificator = null;
    public function __construct(WC_Product $product)
    {
        $this->product = $product;
    }
    public function set_avail_modificator(ProductFieldValueModificator $modificator): void
    {
        $this->modificator = $modificator;
        $this->modificator->set_product($this->product);
    }
    public static function get_key(): string
    {
        return self::KEY;
    }
    public static function get_name(): string
    {
        return esc_attr__('Avail', 'dropshipping-export-free');
    }
    public function has_string_value(): bool
    {
        return \is_string($this->get_string_value());
    }
    public function get_string_value(): ?string
    {
        if ($this->value !== null) {
            return $this->value;
        }
        if (isset($this->modificator) && $this->modificator instanceof ProductFieldStringValue && $this->modificator->has_string_value()) {
            $this->value = $this->modificator->get_string_value();
        } else {
            $this->value = $this->product->get_stock_status();
        }
        return $this->value;
    }
}
