import type { ServerRead } from "@mmapp/contracts/servers"
import type { Server } from "@/lib/data"

export function toFrontendServer(server: ServerRead): Server {
  return {
    id: String(server.id),
    name: server.name || server.host,
    host: server.host,
    type: server.type,
    site: server.site,
    country: server.country,
    asn: server.asn,
    model: server.model ?? "—",
    os: server.os ?? "—",
    enabled: server.enabled,
    status: server.status ?? "offline",
    latency: server.latency != null ? Math.round(server.latency) : null,
    sessions: server.sessions ?? 0,
    comment: server.comment || undefined,
    lanSubnet: server.lanSubnet || undefined,
    wanUplinks: Array.isArray(server.wanUplinks) && server.wanUplinks.length ? server.wanUplinks : undefined,
    uptime: server.uptime ?? undefined,
    cpuLoad: server.cpuLoad ?? undefined,
    freeMemory: server.freeMemory ?? undefined,
    totalMemory: server.totalMemory ?? undefined,
    polledAt: server.polledAt ?? undefined,
  }
}
