<?php

	use Reflect\{Response, Path};

	use VLW\API\API;
	use VLW\Database\Models\Work\{Work, Tag};

	require_once Path::root("src/API/API.php");
	require_once Path::root("src/Database/Models/Work/Tag.php");
	require_once Path::root("src/Database/Models/Work/Work.php");

	final class GET_Work extends API {
		private static function entity(Work $work): object {
			return (object) [
				"tags"    => array_map(fn(Tag $tag): string => $tag->label->name, Tag::from($work)),
				"actions" => [],
				"details" => $work
			];
		}

		public function __construct() {
			parent::__construct();
		}

		public function main(): Response {
			return new Response(array_map(fn(Work $work): object => self::entity($work), Work::all()));
		}
	}