<?php

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

use WC_Product;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldValueModificator;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldStringValue;
class GmcAvailProductFieldModificator implements ProductFieldValueModificator, ProductFieldStringValue
{
    public const IN_STOCK = 'in_stock';
    public const OUT_OF_STOCK = 'out_of_stock';
    public const PREORDER = 'preorder';
    public const BACKORDER = 'backorder';
    private ?WC_Product $product = null;
    public function has_string_value(): bool
    {
        return \is_string($this->get_string_value());
    }
    public function get_string_value(): ?string
    {
        if (!\is_object($this->product)) {
            return null;
        }
        if ($this->product->is_in_stock()) {
            return self::IN_STOCK;
        } elseif ($this->product->is_on_backorder()) {
            return self::BACKORDER;
        }
        return self::OUT_OF_STOCK;
    }
    public function set_product(WC_Product $product): void
    {
        $this->product = $product;
    }
}
