<?php

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

	use VLW\Database\Database;
	use VLW\Database\Tables\Work\WorkTable;

	require_once Path::root("src/Database/Database.php");
	require_once Path::root("src/Database/Tables/Work/Work.php");

	class GET_Work extends Database {
		protected Ruleset $ruleset;

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

			$this->ruleset->GET([
				(new Rules(WorkTable::ID->value))
					->type(Type::STRING)
					->min(1)
					->max(parent::SIZE_VARCHAR),

				(new Rules(WorkTable::TITLE->value))
					->type(Type::STRING)
					->max(parent::SIZE_VARCHAR),

				(new Rules(WorkTable::SUMMARY->value))
					->type(Type::STRING)
					->max(parent::SIZE_TEXT),

				(new Rules(WorkTable::CREATED->value))
					->type(Type::STRING)
					->min(1)
					->max(parent::SIZE_VARCHAR)
			]);

			$this->ruleset->validate_or_exit();

			parent::__construct();
		}

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