<?php

require_once __DIR__ . '/../Fury/fury.php';
require_once __DIR__ . '/TestApp.php';
require_once __DIR__ . '/../../automation/ModesRegistry.php';

// PHPUnit auto-loads via composer, but Fury's own autoloader
// handles the legacy namespace-to-path mapping.
// We just need to ensure Fury/__autoload.php is included (done via fury.php).

$tb = new \Fury\Modules\ThinBuilder\ThinBuilder([
	'dblib' => 'sqlite',
	'dbname' => ':memory:',
], null, false);

$testApp = new TestApp();
$testApp->thin_builder = $tb;
$testApp->utils = new \SHServ\Utils();
$testApp->devtools = new \SHServ\DevTools();
$testApp->scripts_registry = new \SHServ\Middleware\ScriptsRegistry();
$testApp->scripts_registry->flush();
$testApp->modes_context = new \SHServ\Middleware\ModesContext();

\Fury\Kernel\AppContainer::set_app($testApp);

if (!defined('PHPUNIT_TEST')) {
	define('PHPUNIT_TEST', true);
}

// Minimal FCONF for message lookups in Utils
if (!defined('FCONF')) {
	define('FCONF', [
		'app_name' => 'TestApp',
		'text_msgs' => [
			'not_found' => 'Not found',
			'invalid_request' => 'Invalid request',
			'rate_limit_exceeded' => 'Too many requests',
			'unauthorized' => 'Unauthorized',
			'forbidden' => 'Forbidden',
			'device_not_found' => 'Device not found',
			'script_not_exists' => 'Script not found',
			'area_not_found' => 'Area not found',
			'invalid_input' => 'Invalid input',
			'internal_error' => 'Internal server error',
			'invalid_alias' => 'Invalid alias format',
			'empty_field' => 'Field cannot be empty',
			'alias_already_exists' => 'Alias already exists',
			'invalid_id' => 'Invalid identifier',
			'area_not_exists' => 'Area does not exist',
			'undefined_error' => 'Undefined error',
			'invalid_ip' => 'Invalid IP address',
			'invalid_json' => 'Invalid JSON format',
			'invalid_params' => 'Invalid parameters',
			'invalid_action' => 'Invalid action alias',
			'invalid_state' => 'Invalid state value',
			'wrong_status_name' => 'Wrong status name',
			'action_script_not_found' => 'Action script not found',
			'scope_not_found' => 'Scope not found',
			'file_not_exists' => 'File does not exist',
			'invalid_path' => 'Invalid path',
			'device_request_fail' => 'Device request failed',
			'parent_area_not_found' => 'Parent area not found',
		],
		'logs_enable' => false,
		'logs_folder' => __DIR__ . '/Logs',
		'device_ip_range' => ['192.168.1.2', '192.168.1.254'],
		'device_offline_threshold' => 300,
	]);
}

\Fury\Kernel\AppContainer::set_logging(new \Fury\Kernel\Logging());
