<?php

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

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldStringValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldValue;
use WC_Product;
class SingleAttributeProductFieldValue implements ProductFieldValue, ProductFieldStringValue
{
    public const KEY = 'name';
    private ?string $value = null;
    private WC_Product $product;
    private string $taxonomy_name;
    public function __construct(WC_Product $product, string $taxonomy_name)
    {
        $this->product = $product;
        $this->taxonomy_name = $taxonomy_name;
    }
    public static function get_key(): string
    {
        return self::KEY;
    }
    public static function get_name(): string
    {
        return esc_attr__('Product name', 'dropshipping-export-free');
    }
    public function has_string_value(): bool
    {
        return \is_string($this->get_string_value());
    }
    public function get_string_value(): ?string
    {
        $string = (string) $this->product->get_attribute($this->taxonomy_name);
        return $string === '' ? null : $string;
    }
}
