import { join } from 'path';
import { WebServer } from './WebServer/WebServer';
import { homedir } from 'os';
import {
	Config,
	ConfigurationManager,
} from './Configuration/ConfigurationManager';
import { CameraRunner } from './CameraRunner';
import { UnityRunner } from './Unity/UnityRunner';
import { UnityWebSocket } from './Unity/UnityWebSocket';

export class Main {
	dataPath = join(homedir(), 'MorphixProductions', 'NTSHControl');

	ConfigurationManager = new ConfigurationManager(this);
	WebServer = new WebServer(this);

	CameraRunner = new CameraRunner(this);
	UnityRunner = new UnityRunner(this);
	UnityWebSocket = new UnityWebSocket(this);

	Config: Config;

	async start() {
		await this.ConfigurationManager.load();
		await this.WebServer.listen();

		await this.CameraRunner.connect();

		setTimeout(() => {
			this.UnityRunner.start();
		}, this.Config.unity.executable.startUpDelay ?? 0);
	}
}
