<?php

	namespace VLW\Database\Models\Work;

	use \VV;

	use VLW\API\Endpoints;
	use VLW\Database\Models\Model;
	use VLW\Database\Models\Work\Work;
	use VLW\Database\Tables\Work\TimelineTable;

	require_once VV::root("src/API/Endpoints.php");
	require_once VV::root("src/Database/Models/Model.php");
	require_once VV::root("src/Database/Models/Work/Work.php");
	require_once VV::root("src/Database/Tables/Work/Timeline.php");

	class Timeline extends Model {
		public function __construct(public readonly string $id) {
			parent::__construct(Endpoints::WORK_TIMELINE, [
				TimelineTable::REF_WORK_ID->value => $this->id
			]);
		}

		public static function all(array $params = []): array {
			return array_map(fn(array $item): Timeline => new Timeline($item[TimelineTable::REF_WORK_ID->value]), parent::list(Endpoints::WORK_TIMELINE, $params));
		}

		public function work(): Work {
			return new Work($this->get(TimelineTable::REF_WORK_ID->value));
		}

		public function year(): int {
			return $this->get(TimelineTable::YEAR->value);
		}

		public function month(): int {
			return $this->get(TimelineTable::MONTH->value);
		}

		public function day(): int {
			return $this->get(TimelineTable::DAY->value);
		}
	}