const DEFAULT_PORT = 3000;
export class StartDaemonUseCase {
    deps;
    constructor(deps) {
        this.deps = deps;
    }
    execute(input) {
        if (!input.daemon) {
            return { status: 'foreground' };
        }
        const existing = this.deps.readPidFile();
        if (existing && this.deps.isProcessRunning(existing.pid)) {
            return { status: 'already-running', pid: existing.pid, port: existing.port };
        }
        const pid = this.deps.spawnDaemon(input.port);
        const port = input.port ?? DEFAULT_PORT;
        this.deps.writePidFile({
            pid,
            startedAt: new Date().toISOString(),
            port,
        });
        return { status: 'started', pid };
    }
}
//# sourceMappingURL=startDaemon.usecase.js.map