import { env } from "@/lib/env";
import { router } from "./router";
import type { Server } from "bun";

export class WebServer {
    private static server: Server<unknown> | null = null;

    public static start() {
        this.server = Bun.serve({
            port: env.PORT || 3000,
            fetch: router,
        });

        console.log(`🌐 Web server listening on http://localhost:${this.server.port}`);
    }

    public static stop() {
        if (this.server) {
            this.server.stop();
            console.log("🛑 Web server stopped");
            this.server = null;
        }
    }
}
