<?php

namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Integration;

use WC_Product;
class GpsrIntegration
{
    public const FIELD_NAME = 'name';
    public const FIELD_COUNTRY = 'country';
    public const FIELD_CITY = 'city';
    public const FIELD_POSTCODE = 'postcode';
    public const FIELD_ADDRESS = 'address';
    public const FIELD_EMAIL = 'email';
    public const FIELD_PHONE = 'phone';
    public const FIELD_INSTRUCTIONS_TYPE = 'type';
    public const FIELD_INSTRUCTIONS_DATA = 'instructions';
    public const META_IMPORTER_NAME = '_gpsr_importer_name';
    public const META_IMPORTER_COUNTRY = '_gpsr_importer_country';
    public const META_IMPORTER_CITY = '_gpsr_importer_city';
    public const META_IMPORTER_POSTCODE = '_gpsr_importer_postcode';
    public const META_IMPORTER_ADDRESS = '_gpsr_importer_address';
    public const META_IMPORTER_EMAIL = '_gpsr_importer_email';
    public const META_IMPORTER_PHONE = '_gpsr_importer_phone';
    public const META_MANUFACTURER_NAME = '_gpsr_manufacturer_name';
    public const META_MANUFACTURER_COUNTRY = '_gpsr_manufacturer_country';
    public const META_MANUFACTURER_CITY = '_gpsr_manufacturer_city';
    public const META_MANUFACTURER_POSTCODE = '_gpsr_manufacturer_postcode';
    public const META_MANUFACTURER_ADDRESS = '_gpsr_manufacturer_address';
    public const META_MANUFACTURER_EMAIL = '_gpsr_manufacturer_email';
    public const META_MANUFACTURER_PHONE = '_gpsr_manufacturer_phone';
    public const META_INSTRUCTIONS_TYPE = '_gpsr_instructions_type';
    public const META_INSTRUCTIONS_FILE = '_gpsr_instructions_file';
    public const META_INSTRUCTIONS_TEXT = '_gpsr_instructions_text';
    public const VALUE_INSTRUCTIONS_FILE = 'file';
    public const VALUE_INSTRUCTIONS_TEXT = 'text';
    public static function is_active(): bool
    {
        return is_plugin_active('gpsr-for-woocommerce/gpsr-for-woocommerce.php');
    }
    public static function get_responsible_person_data(WC_Product $product): array
    {
        return [self::FIELD_NAME => $product->meta_exists(self::META_IMPORTER_NAME) ? $product->get_meta(self::META_IMPORTER_NAME, \true) : '', self::FIELD_COUNTRY => $product->meta_exists(self::META_IMPORTER_COUNTRY, \true) ? $product->get_meta(self::META_IMPORTER_COUNTRY, \true) : '', self::FIELD_CITY => $product->meta_exists(self::META_IMPORTER_CITY, \true) ? $product->get_meta(self::META_IMPORTER_CITY, \true) : '', self::FIELD_POSTCODE => $product->meta_exists(self::META_IMPORTER_POSTCODE, \true) ? $product->get_meta(self::META_IMPORTER_POSTCODE, \true) : '', self::FIELD_ADDRESS => $product->meta_exists(self::META_IMPORTER_ADDRESS, \true) ? $product->get_meta(self::META_IMPORTER_ADDRESS, \true) : '', self::FIELD_EMAIL => $product->meta_exists(self::META_IMPORTER_EMAIL, \true) ? $product->get_meta(self::META_IMPORTER_EMAIL, \true) : '', self::FIELD_PHONE => $product->meta_exists(self::META_IMPORTER_PHONE, \true) ? $product->get_meta(self::META_IMPORTER_PHONE, \true) : ''];
    }
    public static function get_responsible_producer_data(WC_Product $product): array
    {
        return [self::FIELD_NAME => $product->meta_exists(self::META_MANUFACTURER_NAME) ? $product->get_meta(self::META_MANUFACTURER_NAME, \true) : '', self::FIELD_COUNTRY => $product->meta_exists(self::META_MANUFACTURER_COUNTRY, \true) ? $product->get_meta(self::META_MANUFACTURER_COUNTRY, \true) : '', self::FIELD_CITY => $product->meta_exists(self::META_MANUFACTURER_CITY, \true) ? $product->get_meta(self::META_MANUFACTURER_CITY, \true) : '', self::FIELD_POSTCODE => $product->meta_exists(self::META_MANUFACTURER_POSTCODE, \true) ? $product->get_meta(self::META_MANUFACTURER_POSTCODE, \true) : '', self::FIELD_ADDRESS => $product->meta_exists(self::META_MANUFACTURER_ADDRESS, \true) ? $product->get_meta(self::META_MANUFACTURER_ADDRESS, \true) : '', self::FIELD_EMAIL => $product->meta_exists(self::META_MANUFACTURER_EMAIL, \true) ? $product->get_meta(self::META_MANUFACTURER_EMAIL, \true) : '', self::FIELD_PHONE => $product->meta_exists(self::META_MANUFACTURER_PHONE, \true) ? $product->get_meta(self::META_MANUFACTURER_PHONE, \true) : ''];
    }
    public static function get_instructions(WC_Product $product): array
    {
        $type = $product->meta_exists(self::META_INSTRUCTIONS_TYPE) ? $product->get_meta(self::META_INSTRUCTIONS_TYPE, \true) : '';
        $instructions = '';
        if (self::VALUE_INSTRUCTIONS_FILE === $type) {
            $instructions = $product->meta_exists(self::META_INSTRUCTIONS_FILE) ? $product->get_meta(self::META_INSTRUCTIONS_FILE, \true) : '';
        } elseif (self::VALUE_INSTRUCTIONS_TEXT === $type) {
            $instructions = $product->meta_exists(self::META_INSTRUCTIONS_TEXT) ? $product->get_meta(self::META_INSTRUCTIONS_TEXT, \true) : '';
        }
        return [self::FIELD_INSTRUCTIONS_TYPE => $type, self::FIELD_INSTRUCTIONS_DATA => $instructions];
    }
}
