import fs from 'fs';
import path from 'path';
import { findPackageRoot } from './config.js';
/**
 * Resolve the server entry point and dashboard dist directory.
 * Prefers bundled server from the npm package; falls back to monorepo paths.
 */
export function resolveServerPaths() {
    // 1. Bundled package paths (npm / npx usage)
    const pkgRoot = findPackageRoot();
    const bundledServer = path.join(pkgRoot, 'dist', 'server', 'index.js');
    const bundledDashboard = path.join(pkgRoot, 'dist', 'dashboard');
    if (fs.existsSync(bundledServer) && fs.existsSync(bundledDashboard)) {
        return {
            serverEntry: bundledServer,
            dashboardDist: bundledDashboard,
            cwd: pkgRoot,
        };
    }
    // 2. Monorepo development fallback
    const projectRoot = process.cwd();
    const monoServer = path.join(projectRoot, 'server', 'dist', 'index.js');
    const monoDashboard = path.join(projectRoot, 'dashboard', 'dist');
    return {
        serverEntry: monoServer,
        dashboardDist: monoDashboard,
        cwd: path.join(projectRoot, 'server'),
    };
}
