<?php class session extends basesession {

	/**
	 * Whether the current user is a technician.
	 * @return bool true if the user is a technician, otherwise false.
	 * @throws BadRequestException
	 * @throws ServerException
	 */
	public static function isTechnician(): bool {
		return session::isA(usergroup::TECHNICIANS);
	}

	/**
	 * Whether the current user is a shipper.
	 * @return bool true if the user is a shipper, otherwise false.
	 * @throws BadRequestException
	 * @throws ServerException
	 */
	public static function isShipper(): bool {
		return session::isA(usergroup::SHIPPERS);
	}

	/**
	 * Whether the current user is in the Plate Destroyers usergroup.
	 * @return bool true if the user is in the Plate Destroyers usergroup, otherwise false.
	 * @throws BadRequestException
	 * @throws ServerException
	 */
	public static function isPlateDestroyer(): bool {
	    return session::isA(usergroup::PLATEDESTROYERS);
	}

    /**
     * Determines whether the current user is in the named usergroup.
     * @param string $groupName The group name.
     * @return bool true if the named group exists and the user is in it, otherwise false.
     * @throws BadRequestException
	 * @throws ServerException
     */
	private static function isA(string $groupName): bool {
		try {
			$group=usergroup::getByName($groupName);
		} catch (NotFoundException){
			return false;
		}
		if(!$group){ return false; }
		return usergroup::userisingroup($group['id']);
	}

}