<?php

/**

 * SensFRX Main Class of App

 *

 */

namespace SensFRX\ReviewCount;

use SensFRX\Common\ApiCalls;

/**

 * Class ReviewCount

 *

 * @package ReviewCount

 */

class ReviewCount {

	private $objAPI;

	public function __construct($objAPI) {

		$this->objAPI = $objAPI;

	}

	public function getReviewCount() {

		$method = 'GET';

		$url = '/review-count';

		return $this->objAPI->callAPI($method, $url);

	}



	public function getReviewQueue($type = 'trans', $from_date = null, $to_date = null) {

		$method = 'GET';

		// Use /trans-review or /reg-review based on type

		$url = ($type === 'reg') ? '/reg-review' : '/trans-review';



		// Add date filtering if provided

		if ($from_date && $to_date) {

			$url .= '?from_date=' . urlencode($from_date) . '&to_date=' . urlencode($to_date);

		}



		return $this->objAPI->callAPI($method, $url);

	}



	public function processReviewAction($item_id, $action, $type = 'trans') {

		$method = 'POST';

		// Use /trans-review or /reg-review based on type

		$url = ($type === 'reg') ? '/reg-review' : '/trans-review';



		$data = array(

			'transaction_id' => $item_id,  // or 'account_id' for reg-review

			'status' => $action,  // 'approved' or 'rejected'

			'notes' => ''

		);

		return $this->objAPI->callAPI($method, $url, $data);

	}



	public function addReviewNote($item_id, $note, $type = 'trans') {

		$method = 'POST';

		// Use /trans-review or /reg-review based on type

		$url = ($type === 'reg') ? '/reg-review' : '/trans-review';



		$data = array(

			'transaction_id' => $item_id,  // or 'account_id' for reg-review

			'status' => 'challenge',  // Keep current status

			'notes' => $note

		);

		return $this->objAPI->callAPI($method, $url, $data);

	}



	public function getReviewStats($date = null, $type = 'both', $from_date = null, $to_date = null) {

		$method = 'GET';

		$url = '/review-stats';



		// Add query parameters

		$params = array();

		

		// Date range takes precedence over single date

		if ($from_date !== null && $to_date !== null) {

			$params['from_date'] = $from_date;  // Format: YYYY-MM-DD

			$params['to_date'] = $to_date;      // Format: YYYY-MM-DD

		} elseif ($date !== null) {

			$params['date'] = $date;  // Format: YYYY-MM-DD (single date)

		}

		

		if ($type !== 'both') {

			$params['type'] = $type;  // 'trans', 'reg', or 'both'

		}



		// Append query string if params exist

		if (!empty($params)) {

			$url .= '?' . http_build_query($params);

		}



		return $this->objAPI->callAPI($method, $url);

	}

}

