<?php
/**
 * Helper functions for article sync.
 *
 * @package flo-sync
 */

namespace NMFS\Sync\Items\Articles;

use NMFS\Admin\Settings_Fields;
use NMFS\Shared;
use Northmill_Online_Shared_Sync\Northmill_Online_Shared\Modules\Admin\Settings\Settings_Fields_Module;

defined( 'ABSPATH' ) || exit;

/**
 * Class Article_Sync_Helpers.
 */
class Article_Sync_Helpers {

	/**
	 * Cache for enabled syncs.
	 *
	 * @var array
	 */
	private static array $enabled_syncs = array();

	/**
	 * Whether article title sync is enabled in settings.
	 *
	 * @return bool
	 */
	public static function is_title_sync_active(): bool {
		return self::is_setting_enabled( Settings_Fields::SYNC_PRODUCT_TITLE );
	}

	/**
	 * Whether article display order sync is enabled in settings.
	 *
	 * @return bool
	 */
	public static function is_display_order_sync_active(): bool {
		return self::is_setting_enabled( Settings_Fields::SYNC_ARTICLE_DISPLAY_ORDER );
	}

	/**
	 * Whether article price sync is enabled in settings.
	 *
	 * @return bool
	 */
	public static function is_price_sync_active(): bool {
		return self::is_setting_enabled( Settings_Fields::SYNC_PRICE );
	}

	/**
	 * Whether article image sync is enabled in settings.
	 *
	 * @return bool
	 */
	public static function is_image_sync_active(): bool {
		return self::is_setting_enabled( Settings_Fields::SYNC_PRODUCT_PICTURES );
	}

	/**
	 * Whether article tax class sync is enabled in settings.
	 *
	 * @return bool
	 */
	public static function is_tax_class_sync_active(): bool {
		return self::is_setting_enabled( Settings_Fields_Module::SYNC_PRODUCT_TAX_CLASS );
	}

	/**
	 * Whether article description sync is enabled in settings.
	 *
	 * @return bool
	 */
	public static function is_desc_sync_active(): bool {
		return self::is_setting_enabled( Settings_Fields::SYNC_PRODUCT_DESCRIPTION );
	}

	/**
	 * Whether article publish status sync is enabled in settings.
	 *
	 * @return bool
	 */
	public static function is_publish_status_sync_active(): bool {
		return self::is_setting_enabled( Settings_Fields::SYNC_PRODUCT_STATUS );
	}

	/**
	 * Check if a setting is enabled.
	 *
	 * @param string $key Setting key.
	 *
	 * @return bool
	 */
	private static function is_setting_enabled( string $key ): bool {
		if ( ! isset( self::$enabled_syncs[ $key ] ) ) {
			self::$enabled_syncs[ $key ] = Shared::instance()->admin->settings->is_setting_enabled( $key );
		}

		return (bool) self::$enabled_syncs[ $key ];
	}
}
