import { createServer } from "node:http"
import { NodeContext, NodeHttpServer, NodeRuntime } from "@effect/platform-node"
import { Effect, Layer } from "effect"
import { ServerConfig } from "./config"
import { Server } from "./server"


Layer.launch(Server).pipe(
    Effect.provide(Layer.empty.pipe(
        Layer.provideMerge(ServerConfig.httpPort.pipe(
            Effect.map(port => NodeHttpServer.layer(createServer, { port })),
            Layer.unwrapEffect,
        )),
        Layer.provideMerge(NodeContext.layer),
    )),

    NodeRuntime.runMain,
)
