<?php

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

use WC_Product;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldIntValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldValue;
class IdProductFieldValue implements ProductFieldValue, ProductFieldIntValue
{
    public const KEY = 'id';
    private ?int $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__('ID', 'dropshipping-export-free');
    }
    public function has_int_value(): bool
    {
        return \is_int($this->get_field_value());
    }
    public function get_int_value(): ?int
    {
        return $this->get_field_value();
    }
    private function get_field_value(): ?int
    {
        if ($this->value !== null) {
            return $this->value;
        }
        $id = $this->product->get_id();
        $result = \is_numeric($id) ? (int) $id : null;
        if (\is_int($result)) {
            $this->value = $result;
        }
        return $this->value;
    }
}
