<?php
/**
 * Events service for handling internal RewardsWP events.
 *
 * @package RewardsWP
 */

namespace Awesomemotive\Rewardswp\Services;

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

use Awesomemotive\Rewardswp\Abstracts\AbstractModelService;
use Awesomemotive\Rewardswp\Database\DatabaseHandler;
use Awesomemotive\Rewardswp\Database\Tables\EventsTable;
use Awesomemotive\Rewardswp\Models\Event;
use DI\Container;

class EventsService extends AbstractModelService {

	/**
	 * Constructor.
	 *
	 * @since 1.0.0
	 *
	 * @param DatabaseHandler $db_handler The database handler.
	 * @param EventsTable     $db_table   The events table.
	 * @param Container       $container  The dependency injection container.
	 */
	public function __construct(
		DatabaseHandler $db_handler,
		EventsTable $db_table,
		Container $container
	) {
		parent::__construct( $db_handler, $db_table, $container );
	}

	/**
	 * Retrieve events based on the given parameters and pagination options.
	 *
	 * @since 1.0.0
	 *
	 * @param array $where An associative array of conditions to filter events.
	 *                     See {@see EventsTable::get_columns()} for available parameters.
	 * @param int   $per_page Optional. The number of items per page for pagination. Defaults to 10.
	 * @param int   $page  Optional. The page number for pagination. Defaults to 1.
	 *
	 * @return Event[] Array of Event objects.
	 */
	public function get_events( array $where = [], int $per_page = 10, int $page = 1 ): array {
		return $this->get_objects( Event::class, $where, $per_page, $page );
	}

	/**
	 * Get the number of events based on the given parameters.
	 *
	 * @since 1.0.0
	 *
	 * @param array $where An associative array of conditions to filter events.
	 *                     See {@see EventsTable::get_columns()} for available parameters.
	 * @return int The number of entries found.
	 */
	public function count_events( array $where = [] ): int {
		return $this->count_objects( $where );
	}
}
