<?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\{TagsTable, TagsLabelEnum};

	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/Tags.php");

	class Tag extends Model {
		public function __construct() {
			parent::__construct();
		}

		public static function all(array $params = []): array {
			return array_map(fn(array $item): Tag => (new Tag())->assign($item), parent::list(Endpoints::WORK_TAGS, $params));
		}

		public static function from(Work $work): array {
			return self::all([
				TagsTable::REF_WORK_ID->value => $work->id
			]);
		}

		public function label(): TagsLabelEnum {
			return TagsLabelEnum::fromName($this->get(TagsTable::LABEL->value));
		}
	}