<?php

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

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Integration\EanIntegration;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldStringValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldValue;
use WC_Product;
class EanProductFieldValue implements ProductFieldValue, ProductFieldStringValue
{
    public const KEY = 'ean';
    private ?string $value = null;
    private WC_Product $product;
    public function __construct(WC_Product $product)
    {
        $this->product = $product;
    }
    public static function get_key(): string
    {
        return self::KEY;
    }
    public static function get_name(): string
    {
        return esc_attr__('EAN', 'dropshipping-export-free');
    }
    public function has_string_value(): bool
    {
        return \is_string($this->get_field_value());
    }
    public function get_string_value(): ?string
    {
        return $this->get_field_value();
    }
    private function get_field_value(): ?string
    {
        if ($this->value !== null) {
            return $this->value;
        }
        $ean = EanIntegration::get_ean_field($this->product);
        $this->value = \is_string($ean) >= 1 ? $ean : null;
        return $this->value;
    }
}
