<?php

namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ConditionalLogic\Fields;

use WC_Product;
use WC_Product_Variation;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ConditionalLogic\Fields\Abstraction\WPTaxonomyField;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ConditionalLogic\Fields\Abstraction\Field;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ConditionalLogic\Fields\Abstraction\AllowedConditions;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ConditionalLogic\Conditions\IsInCategoryCondition;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\ConditionalLogic\Conditions\IsNotInCategoryCondition;
class CategoryField implements Field, WPTaxonomyField, AllowedConditions
{
    public function get_product_value(WC_Product $product)
    {
        if ($product instanceof WC_Product_Variation) {
            $parent_id = $product->get_parent_id();
            $product = wc_get_product($parent_id);
        }
        return $product->get_category_ids();
    }
    public static function get_allowed_conditions(): array
    {
        return [IsInCategoryCondition::class, IsNotInCategoryCondition::class];
    }
    public static function get_name(): string
    {
        return 'category';
    }
    public static function get_nice_name(): string
    {
        return __('Category name', 'dropshipping-export-free');
    }
    public static function get_taxonomy(): string
    {
        return 'product_cat';
    }
    public static function get_taxonomy_field(): string
    {
        return 'term_id';
    }
}
