<?php

	namespace VLW\Database\Models\Coffee;

	use \VV;
	use \DateTimeImmutable;

	use VLW\API\Endpoints;
	use VLW\Database\Models\Model;
	use VLW\Database\Tables\Coffee\CoffeeTable;

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

	class Coffee extends Model {
		public function __construct(public readonly string $id) {
			parent::__construct(Endpoints::COFFEE, [
				CoffeeTable::ID->value => $this->id
			]);
		}

		public static function all(array $params = []): array {
			return array_map(fn(array $item): Coffee => new Coffee($item[CoffeeTable::ID->value]), parent::list(Endpoints::COFFEE, $params));
		}

		public function timestamp(): int {
			return $this->get(CoffeeTable::ID->value);
		}

		public function datetime(): DateTimeImmutable {
			return DateTimeImmutable::createFromFormat("U", $this->timestamp());
		}
	}