<?php

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

	use VLW\Database\Database;
	use VLW\Database\Tables\Work\TimelineTable;

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

	class GET_WorkTimeline extends Database {
		protected Ruleset $ruleset;

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

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

				(new Rules(TimelineTable::YEAR->value))
					->type(Type::NUMBER)
					->min(0)
					->max(parent::SIZE_UINT16),

				(new Rules(TimelineTable::MONTH->value))
					->type(Type::NUMBER)
					->min(0)
					->max(parent::SIZE_UINT8),

				(new Rules(TimelineTable::DAY->value))
					->type(Type::NUMBER)
					->min(0)
					->max(parent::SIZE_UINT8)
			]);

			$this->ruleset->validate_or_exit();

			parent::__construct();
		}

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