<?php
/**
 * Turn 14 Filter Hook Registration
 *
 * @package    Common
 * @subpackage Hooks
 */

namespace MOWCPS\Common\Hooks;

use MOWCPS\Common\Constants\Plugin_Filters;
use MOWCPS\Common\Interfaces\Hookable_Interface;
use MOWCPS\Common\Suppliers\Turn14 as Turn14_Supplier;

if ( ! defined( 'ABSPATH' ) ) {
	die;
}

/**
 * Class Turn14
 */
class Turn14 implements Hookable_Interface {

	/**
	 * Initialize the Turn 14 filter hooks
	 */
	public function __construct() {
		$this->register_hooks();
	}

	/**
	 * Register WordPress hooks
	 *
	 * Simplified pagination following SNS pattern - restart-safe!
	 *
	 * @return void
	 */
	public function register_hooks() {
		// Clean cache before fresh sync starts (ensures clean slate)
		add_action(
			Plugin_Filters::FILTER_PERFORM_ACTION_BEFORE_SYNC,
			array( Turn14_Supplier::class, 'clean_cache_before_sync' ),
			10,
			1
		);

		// Extract max pages from API response metadata (links.last)
		add_filter(
			Plugin_Filters::FILTER_API_CALL_ALTERATION_FILTER,
			array( Turn14_Supplier::class, 'extract_brand_max_pages' ),
			10,
			1
		);

		// Inject brand ID into URLs & handle brand switching proactively
		add_filter(
			Plugin_Filters::FILTER_DATA_ALTERATION_FILTER,
			array( Turn14_Supplier::class, 'inject_brand_into_pagination_url' ),
			10,
			1
		);

		// Process completion - continue pagination across brands
		add_filter(
			Plugin_Filters::FILTER_SUPPLIER_PROCESS_COMPLETION,
			array( Turn14_Supplier::class, 'handle_process_completion' ),
			10,
			1
		);

		// Final sync end status modification - override "Page X completed" when all brands are done
		add_filter(
			Plugin_Filters::FILTER_ALTER_PRODUCT_SYNC_AUDIT,
			array( Turn14_Supplier::class, 'handle_final_sync_end_status' ),
			10,
			1
		);

		// Modify stock quantity for Turn14 - use manufacturer stock instead of warehouse inventory
		add_filter(
			Plugin_Filters::FILTER_MODIFY_STOCK_BEFORE_SET,
			array( Turn14_Supplier::class, 'modify_turn14_stock_quantity' ),
			10,
			1
		);
	}
}
