<?php

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

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldArrayValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldValue;
use WC_Product;
class GpsrProductFieldValue implements ProductFieldValue, ProductFieldArrayValue
{
    public const KEY_PRODUCER = 'producer';
    public const KEY_IMPORTER = 'importer';
    public const KEY_SAFETY = 'safety';
    public const KEY = 'gpsr';
    private ?array $value = null;
    private ResponsibleProducersProductFieldValue $producer;
    private ResponsiblePersonProductFieldValue $importer;
    private SafetyInstructionsProductFieldValue $safety;
    public function __construct(WC_Product $product)
    {
        $this->producer = new ResponsibleProducersProductFieldValue($product);
        $this->importer = new ResponsiblePersonProductFieldValue($product);
        $this->safety = new SafetyInstructionsProductFieldValue($product);
    }
    public static function get_key(): string
    {
        return self::KEY;
    }
    public static function get_name(): string
    {
        return esc_attr__('GPSR', 'dropshipping-export-free');
    }
    public function has_array_value(): bool
    {
        return \is_array($this->get_array_value());
    }
    public function get_array_value(): ?array
    {
        if ($this->value !== null) {
            return $this->value;
        }
        $value = [];
        $value[self::KEY_IMPORTER] = $this->importer->get_array_value();
        $value[self::KEY_PRODUCER] = $this->producer->get_array_value();
        $value[self::KEY_SAFETY] = $this->safety->get_array_value();
        $this->value = $value;
        return $this->value;
    }
}
