<?php

namespace SHServ\Models;

use \SHServ\Tools\DeviceAPI\Base;
use \SHServ\Entities\Device;
use \SHServ\Entities\DeviceAuth;

class EventsModel extends \SHServ\Middleware\Model {

	public function global_any_device_event_call($device, $event_name, $data) {
		return events() -> app_call(
			$event_name,
			[
				"device" => $device,
				"data" => $data	
			]
		);
	}	

	public function global_device_event_call($device, $event_name, $data) {
		return events() -> app_call(
			"{$device -> device_type}.{$event_name}",
			[
				"device" => $device,
				"data" => $data	
			]
		);
	}	

	public function channel_device_event_call($device, $event_name, $channel_index, $data) {
		return events() -> app_call(
			"{$device -> device_type}({$channel_index}).{$event_name}",
			[
				"device" => $device,
				"data" => $data	
			]
		);
	}	

	public function alias_device_event_call($device, $event_name, $data) {
		$alias = $device -> alias;
		return events() -> app_call(
			"{$device -> device_type}@{$alias}.{$event_name}",
			[
				"device" => $device,
				"data" => $data	
			]
		);
	}

	public function channel_alias_device_event_call($device, $event_name, $channel_index, $data) {
		$alias = $device -> alias;
		return events() -> app_call(
			"{$device -> device_type}@{$alias}({$channel_index}).{$event_name}",
			[
				"device" => $device,
				"data" => $data	
			]
		);
	}	
}