<?php
namespace SabaiApps\Framework\DB;

/**
 * AbstractRowset class for managing database rowsets.
 * Implements IteratorAggregate and Countable interfaces for flexible rowset traversal and counting.
 */
abstract class AbstractRowset implements \IteratorAggregate, \Countable {

	/**
	 * Gets an iterator for traversing the rowset.
	 *
	 * @return RowsetIterator Iterator object for the rowset.
	 */
	#[\ReturnTypeWillChange]
	public function getIterator() {
		return new RowsetIterator( $this );
	}

	/**
	 * Counts the number of rows in the rowset.
	 * Implementation of the Countable interface.
	 *
	 * @return int Number of rows.
	 */
	#[\ReturnTypeWillChange]
	public function count() {
		return $this->rowCount();
	}

	/**
	 * Fetches the first column value from the current row.
	 *
	 * @return string Column value.
	 */
	public function fetchSingle() {
		return $this->fetchColumn( 0 );
	}

	/**
	 * Fetches a single column value from the current row.
	 *
	 * @param int $index Column index (default is 0).
	 * @return string Column value.
	 */
	abstract public function fetchColumn( $index = 0 );

	/**
	 * Fetches the current row as an associative array.
	 *
	 * @return array Associative array of row data.
	 */
	abstract public function fetchAssoc();

	/**
	 * Fetches the current row as a numeric array.
	 *
	 * @return array Numeric array of row data.
	 */
	abstract public function fetchRow();

	/**
	 * Moves the internal pointer to the specified row offset.
	 *
	 * @param int $offset Row offset.
	 * @return bool True on success, false on failure.
	 */
	abstract public function seek( $offset = 0 );

	/**
	 * Gets the number of rows in the rowset.
	 *
	 * @return int Number of rows.
	 */
	abstract public function rowCount();
}
