<?php

	use vlw\MySQL\Order;
	use Reflect\{Response, Path, Call};
	use Reflect\Rules\{Ruleset, Rules, Type};

	use VLW\API\Endpoints;
	use VLW\Database\Database;
	use VLW\Database\Tables\Coffee\CoffeeTable;

	require_once Path::root("src/API/Endpoints.php");
	require_once Path::root("src/Database/Database.php");
	require_once Path::root("src/Database/Tables/Coffee/Coffee.php");

	class GET_Coffee extends Database {
		protected readonly Ruleset $ruleset;

		public function __construct() {
			$this->ruleset = new Ruleset(strict: true);

			$this->ruleset->GET([
				(new Rules(CoffeeTable::ID->value))
					->type(Type::NUMBER)
					->min(1)
					->max(parent::SIZE_UINT32)
			]);

			$this->ruleset->validate_or_exit();

			parent::__construct();
		}

		public function main(): Response {
			return $this->list(CoffeeTable::NAME, CoffeeTable::values(), [
				CoffeeTable::ID->value => Order::DESC
			]);
		}
	}