<?php

namespace SHServ\Tools\DeviceAPI;

class Button extends Base {
	public function get_indicators(): Array {
		$status_response = $this -> get_status();

		if($status_response["status"] != "ok") {
			return [];
		}

		return [
			"indicators" => $status_response["indicators"] ?? null,
			"channels" => $status_response["channels"] ?? []
		];
	}

	public function get_indicator_state(int $channel_id = 0): String | null {
		$indicators = $this -> get_indicators();

		foreach($indicators["channels"] as $channel) {
			if($channel["id"] == $channel_id) {
				return $channel["indicator"];
			}
		}

		return null;
	}

	public function set_channel_state(String $state_mode, int $channel_id): Array | null {
		$modes = [
			"enabled",
			"disabled",
			"mute",
			"waiting",
			"warning",
			"error"
		];

		if(!in_array($state_mode, $modes)) {
			$state_mode = "error";
		}

		return $this -> post_action("set_channel_state", [
			"state" => $state_mode,
			"channel" => $channel_id
		]);
	}
}