<?php
/**
 * Define a resource Type.
 * @author Idleman
 * @category Plugin
 * @license copyright
 */
class ResourceType{

	public static function types($slug=null){

		$typefiles = array();
		Plugin::callHook('hackpoint_resource_type',array(&$typefiles));

		$types = array();
		foreach($typefiles as $file){

			$class = str_replace('.class.php','',basename($file));
			require_once($file);
	
			if(!method_exists ( $class , 'toHtml' )) continue;
			if(!method_exists ( $class , 'toJson' )) continue;
			if(!method_exists ( $class , 'toFile' )) continue;
			if(!method_exists ( $class , 'fromJson' )) continue;
			if(!method_exists ( $class , 'fromFile' )) continue;
			
			
			$infos = $class::manifest();
			$infos['class'] = $class;
			$infos['path'] = $file;
			$types[$infos['uid']] = $infos;

		}

		// $type = new ResourceType();
		// $type->color = '#20c997';
		// $type->icon = 'fas fa-code';
		if(!isset($slug)) return $types;
		return isset($types[$slug]) ? $types[$slug] : false;
	}
}
?>