<?php declare(strict_types = 0);
/*
** Copyright (C) 2021-2026 initMAX s.r.o.
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/

namespace Modules\TetrisMAX\Actions;

use CControllerDashboardWidgetView;
use CControllerResponseData;
use Modules\TetrisMAX\Includes\GamePayload;

/**
 * tetrisMAX view action for Zabbix 6.4 - 7.4.
 *
 * The ONLY server round trip the widget makes, and it makes it once: the
 * dashboard asks for the tile's contents, this hands back the board and the
 * shapes, and the game then runs entirely in the browser. Nothing is written
 * anywhere and no Zabbix API is called.
 *
 * The base class is the only real difference from the 6.0/6.2 controller: that
 * line has no CControllerDashboardWidgetView. What the browser receives is
 * built by the shared GamePayload, so the two trees cannot answer differently.
 */
class WidgetView extends CControllerDashboardWidgetView
{
	protected function doAction(): void
	{
		$this->setResponse(new CControllerResponseData(
			GamePayload::build($this->fields_values) + [
				'name' => $this->getInput('name', $this->widget->getName()),
				'user' => [
					'debug_mode' => $this->getDebugMode()
				]
			]
		));
	}
}
