<?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\ActionsTable;

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

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

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

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

		public function icon_prepended(): ?string {
			return $this->get(ActionsTable::ICON_PREPENDED->value);
		}

		public function icon_appended(): ?string {
			return $this->get(ActionsTable::ICON_APPENDED->value);
		}

		public function display_text(): string {
			return $this->get(ActionsTable::DISPLAY_TEXT->value);
		}

		public function href(): ?string {
			return $this->get(ActionsTable::HREF->value);
		}

		public function classes(): array {
			return $this->get(ActionsTable::CLASS_LIST->value) ? explode(",", $this->get(ActionsTable::CLASS_LIST->value)) : [];
		}
	}