<?php

interface DatabaseInterface
{
	public const ORDER_ASC = true;
	public const ORDER_DESC = false;

	/**
	 * Has to close the connection.
	 */
	public function __destruct();

	/**
	 * Sends an sql query to the database.
	 */
	public function Query(string $query, array $params = []): void;

	/**
	 * @return array
	 */
	public function getResult(): array;

	/**
	 * Selects backend from a table.
	 */
	public function Select(
		string $tableName,
		array $fields = [],
		array $conditions = [],
		int $limit = 0,
		array $orderBy = [],
		bool $asc = true,
		int $offset = 0
	): array;

	/**
	 * Deletes rows from a table.
	 */
	public function Delete(string $table, array $conditions): void;

	/**
	 * Inserts a new row into the table.
	 */
	public function Insert(string $table, array $fields): ?int;

	/**
	 * Edits backend inside a table.
	 */
	public function Update(string $table, array $fields, array $conditions): void;

	/**
	 * Returns the number of entries found.
	 */
	public function Count(string $table, array $conditions = []): int;

	/*
	 * Returns if there's an open transaction.
	 */
	public function hasTransaction(): bool;

	/*
	 * Starts a transaction that can later be committed or rolled back.
	 */
	public function startTransaction(): void;

	/*
	 * Quits a current transaction without saving.
	 */
	public function rollback(): void;

	/*
	 * Saves and exits a current transaction.
	 */
	public function commit(): void;

	/**
	 * Returns the primary key from the last inserted row.
	 */
	public function GetLastInsertedId(): int;
}