<?php

namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Factory;

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Service\Dependency\Resolver\Abstraction\DependencyResolverInterface;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\CategoryProductFieldValue;
use WC_Product;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\AttributesProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\AvailProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\DescriptionProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\EanProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\IdProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\ImageProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\NameProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\ParentIdProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\PriceProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\RegularPriceProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\SalePriceProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\ShortDescriptionProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\SkuProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\StockProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\UrlProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\ProductFieldValue;
use RuntimeException;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Integration\GpsrIntegration;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\PriceCompare\ProductFields\Custom\ResponsibleProducerField;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\GpsrProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\CustomTextProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\GmcConditionProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\NoProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\ResponsiblePersonProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\SafetyInstructionsProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\SingleAttributeProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\WeightProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\ResponsibleProducersProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\GmcIdentifierExistsProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\BrandProductFieldValue;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ProductFields\Value\GmcShippingProductFieldValue;
class ProductFieldsValueFactory
{
    private DependencyResolverInterface $resolver;
    public function __construct(DependencyResolverInterface $dependency_resolver)
    {
        $this->resolver = $dependency_resolver;
    }
    public function get_all(WC_Product $product, array $exclude_ids = []): array
    {
        $result = [];
        $classes = $this->get_all_classes();
        foreach ($classes as $class) {
            if (!\in_array($class::get_key(), $exclude_ids, \true)) {
                $result[$class::get_key()] = $this->resolver->resolve($class, ['product' => $product]);
            }
        }
        return $result;
    }
    public function get(WC_Product $product, string $key): ProductFieldValue
    {
        $classes = $this->get_all_classes();
        foreach ($classes as $class) {
            if (strpos($key, 'pa_') === 0) {
                return $this->resolver->resolve(SingleAttributeProductFieldValue::class, ['product' => $product, 'taxonomy_name' => $key]);
            } elseif ($key === $class::get_key()) {
                return $this->resolver->resolve($class, ['product' => $product]);
            }
        }
        throw new RuntimeException('Product field value' . $key . ' not exists');
    }
    public function get_class_name(string $key): string
    {
        $classes = $this->get_all_classes();
        foreach ($classes as $class) {
            if (strpos($key, 'pa_') === 0) {
                return SingleAttributeProductFieldValue::class;
            } elseif ($key === $class::get_key()) {
                return $class;
            }
        }
        throw new RuntimeException('Product field value' . $key . ' not exists');
    }
    private function get_all_classes(): array
    {
        $result = [NoProductFieldValue::class, CustomTextProductFieldValue::class, GmcIdentifierExistsProductFieldValue::class, GmcConditionProductFieldValue::class, GmcShippingProductFieldValue::class, CategoryProductFieldValue::class, DescriptionProductFieldValue::class, EanProductFieldValue::class, IdProductFieldValue::class, ImageProductFieldValue::class, NameProductFieldValue::class, BrandProductFieldValue::class, ParentIdProductFieldValue::class, PriceProductFieldValue::class, RegularPriceProductFieldValue::class, SalePriceProductFieldValue::class, ShortDescriptionProductFieldValue::class, SkuProductFieldValue::class, StockProductFieldValue::class, WeightProductFieldValue::class, UrlProductFieldValue::class, AvailProductFieldValue::class, AttributesProductFieldValue::class];
        if (GpsrIntegration::is_active()) {
            $result[] = ResponsiblePersonProductFieldValue::class;
            $result[] = ResponsibleProducersProductFieldValue::class;
            $result[] = SafetyInstructionsProductFieldValue::class;
            $result[] = GpsrProductFieldValue::class;
        }
        return $result;
    }
    public function get_key_and_values(array $exclude_ids = []): array
    {
        $result = [];
        $classes = $this->get_all_classes();
        foreach ($classes as $class) {
            if (!\in_array($class::get_key(), $exclude_ids, \true)) {
                $result[$class::get_key()] = $class::get_name();
            }
        }
        return $result;
    }
    public function get_selected_key_and_values(array $ids = []): array
    {
        $result = [];
        $classes = $this->get_all_classes();
        foreach ($classes as $class) {
            if (\in_array($class::get_key(), $ids, \true)) {
                $result[$class::get_key()] = $class::get_name();
            }
        }
        return $result;
    }
}
