<?php
/**
 * Collection of syncers.
 *
 * @package northmill-online-shared
 */

declare(strict_types=1);

namespace Northmill_Online_Shared\Modules\Sync\Models;

use Northmill_Online_Shared\Abstracts\Hub_API\Sync\Ajax\Models\Sync_Request_Model;
use Northmill_Online_Shared\Abstracts\Hub_API\Sync\Cron\Models\Cron_Sync_Model;

defined( 'ABSPATH' ) || exit;

/**
 * Class Sync_Collection_Model
 */
readonly class Sync_Collection_Model {

	/**
	 * Class constructor.
	 *
	 * @param Cron_Sync_Model|null    $cron_syncer Cron syncer model.
	 * @param Sync_Request_Model|null $ajax_syncer Ajax syncer model.
	 */
	public function __construct(
		private ?Cron_Sync_Model $cron_syncer,
		private ?Sync_Request_Model $ajax_syncer
	) {}

	/**
	 * Get the cron syncer.
	 *
	 * @return Cron_Sync_Model|null
	 */
	public function get_cron_syncer(): ?Cron_Sync_Model {
		return $this->cron_syncer;
	}

	/**
	 * Get the ajax syncer.
	 *
	 * @return Sync_Request_Model|null
	 */
	public function get_ajax_syncer(): ?Sync_Request_Model {
		return $this->ajax_syncer;
	}

	/**
	 * Get wp option names of syncer.
	 *
	 * @return array
	 */
	public function get_option_names(): array {
		if ( $this->ajax_syncer ) {
			$syncer = $this->ajax_syncer->syncer;
		} elseif ( $this->cron_syncer ) {
			$syncer = $this->cron_syncer->syncer;
		} else {
			return array();
		}

		return $syncer->get_all_last_synced_wp_option_names();
	}
}
