namespace MiGu.Server.Launcher;
///
/// MiGu.Server 启动后由「平台登录」按 LaunchMode 拉起的 SimpleLite 子进程配置。
///
/// 会话 N+1(启动反转):原架构是 SimpleLite 启动 → 拉 MiGu.Server;现在反过来:
/// MiGu.Server 作为主入口启动 → 登录页选 LaunchMode → 后端拉起 SimpleLite.exe,
/// 通过 --display-mode 参数把 web / web+local 透传给 SimpleLite 的 Configuration。
///
/// 绑定 appsettings.json:SimpleLite。
///
public sealed class SimpleLiteOptions
{
/// 主开关。false = 永不拉起;登录无论选什么 LaunchMode 都不会启动子进程,用于「只跑 Platform 调试」场景。
public bool Enabled { get; set; } = true;
///
/// SimpleLite 可执行文件绝对/相对路径(相对 MiGu.Server 工作目录)。留空则按以下顺序自动探测:
/// 1) ./SimpleLite.exe(合并发布布局:SimpleLite 与 MiGu.Server 同目录)
/// 2) ./SimpleLite/SimpleLite.exe
/// 3) ../SimpleLite.exe(MiGu.Server 部署到子目录的常见布局)
/// 4) ../SimpleLite/bin/Debug/SimpleLite.exe(开发态:Visual Studio 默认输出)
/// 5) ../SimpleLite/bin/Release/SimpleLite.exe
/// 6) 沿父目录上行寻找 SimpleLite/bin/{Debug|Release}/SimpleLite.exe
///
public string ExecutablePath { get; set; } = "";
/// 留空时取 所在目录。SimpleLite 在 CWD 读写 simple.json / imgui.ini,CWD 选错会出意外。
public string WorkingDirectory { get; set; } = "";
/// 附加命令行参数(拼在 --display-mode=xxx 之后)。常用于本地调试时强制 autoload 某场景。
public string Arguments { get; set; } = "";
///
/// 子进程启动后阻塞等待 Projection (:8222) 端口就绪的最长毫秒数。
/// 0 = 不等待(登录立即返回,前端可能还连不上 SimpleLite WebApi);
/// 负值 = 无限等待(直到子进程退出或就绪)。
///
public int ReadinessTimeoutMs { get; set; } = 8000;
/// 每隔多少毫秒 poll 一次 Projection 端口可达性。
public int ReadinessPollIntervalMs { get; set; } = 250;
/// SimpleLite Projection WebApi 监听端口。默认与 SimpleLite Configuration 的 `port` 一致。用于就绪检测。
public int ProjectionPort { get; set; } = 8222;
///
/// 是否把 SimpleLite 绑定到 MiGu.Server 生命周期,默认 false(会话 N+2 用户反馈)。
///
/// 设计原则:SimpleLite 与 MiGu.Server 是「两个独立程序」,Platform 只是登录后顺手拉起 SimpleLite;
/// MiGu.Server 关闭不应该带走 SimpleLite,反之亦然。所以 FollowParent 默认 false:
/// - 子进程走 UseShellExecute=true 创建独立进程组 + 独立控制台窗口;
/// - 不挂 JobObject,不在 ApplicationStopping / ProcessExit 时 kill 子进程;
/// - SimpleLite 退出由用户自己负责(关窗口 / 任务管理器 / 调度内核异常退出)。
///
/// true 仍可用:会启动 Windows JobObject 父子绑定(仅 Windows 有效)+ 注册 ApplicationStopping 软关闭。
/// 一般只在临时联调期 / CI 流水线想自动清理时打开。
///
public bool FollowParent { get; set; } = false;
///
/// 平台拉起 SimpleLite 时是否以「迷榖嵌入画布」模式运行(透传命令行 --migu),默认 true。
///
/// true:平台 iframe 嵌入场景,SimpleLite WebTerminal 默认只显示 3D 画布、隐藏所有 ImGui panel,
/// 业务 UI 全部由 Vue 平台前端接管;declare 时序失败时也安全回退到纯画布。
/// false:平台拉起的 SimpleLite web 端默认显示完整 panel(便于把平台拉起的实例直连 :8223 调试)。
///
/// 与 LaunchMode(web / web+local,是否保留本地调试窗口)正交,可任意组合。
///
public bool EmbeddedCanvas { get; set; } = true;
}