<?php
/**
 * Sync Analytics Handler
 *
 * @category   WordPress_Plugin
 * @package    Standard
 * @subpackage Handlers\Rest_API
 * @author     miniOrange <info@miniorange.com>
 * @license    MIT/Expat
 * @link       https://plugins.miniorange.com/woocommerce-api-product-sync-with-woocommerce-rest-apis
 */

namespace MOWCPS\Standard\Handlers\Rest_API;

use WP_Error;
use MOWCPS\Standard\Models\Product_Sync_Audit_Model;
use MOWCPS\Common\Utils\Model_Utils;

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

/**
 * Class Product_Sync_Audit_Handler
 *
 * Handles sync analytics and reporting operations
 */
class Product_Sync_Audit_Handler {
	/**
	 * Product sync audit model instance
	 *
	 * @var Product_Sync_Audit_Model
	 */
	private $audit_model;

	/**
	 * Constructor
	 */
	public function __construct() {
		$this->audit_model = new Product_Sync_Audit_Model();
	}

	/**
	 * Get product sync audit data
	 *
	 * @param string $mode Optional mode filter. Accepts 'manual', 'automatic', or '' (default - all syncs).
	 * @return array|WP_Error
	 */
	public function get_product_sync_audit( $mode = '' ) {
		$result = $this->audit_model->get_product_sync_audit( $mode );

		if ( is_wp_error( $result ) ) {
			return $result;
		}

		return Model_Utils::sanitize_for_api_response( $result );
	}
}
