import { WebSocketMessageParam } from "@/src/types";
import sendData from "../(utils)/send-data";
import sendError from "../(utils)/send-error";
import grabTtydServerInfo from "@/src/functions/ttyd/grab-ttyd-service-info";

export default async function socketClientServiceServerShell({
    ws,
    data,
}: WebSocketMessageParam) {
    try {
        const user = ws.data.user;
        const service = data?.service;
        const server = data?.server;

        const ttyd = await grabTtydServerInfo({
            server,
            service,
            user,
            paradigm: "terminal",
        });

        sendData(ws, {
            event: "server:service-server-shell",
            ttyd,
            server,
        });
    } catch (error: any) {
        sendError(ws, "Service Server Logs Error! " + error.message);
    }
}
