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 socketClientServiceServerLogs({
    ws,
    data,
}: WebSocketMessageParam) {
    try {
        const user = ws.data.user;
        const service = data?.service;
        const server = data?.server;
        const cmd = data?.cmd;

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

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