<?php

	use Reflect\Rules\Ruleset;
	use Reflect\{Response, Path, Call};

	use VLW\API\Endpoints;
	use VLW\Database\Database;
	use VLW\Database\Tables\About\LanguagesTable;

	require_once Path::root("src/API/Endpoints.php");
	require_once Path::root("src/Database/Database.php");
	require_once Path::root("src/Database/Tables/About/Languages.php");

	class DELETE_AboutLanguages extends Database {
		protected readonly Ruleset $ruleset;

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

			parent::__construct();
		}

		private function languages(): array {
			$resp = (new Call(Endpoints::ABOUT_LANGUAGES->value))->get();

			return array_column($resp->output(), LanguagesTable::ID->value);
		}

		// Delete languages cache file if it exists
		public function main(): Response {
			$this->db->for(LanguagesTable::NAME);

			foreach ($this->languages() as $language){
				$this->db->delete([LanguagesTable::ID->value => $language]);
			}

			return new Response();
		}
	}