package Webpage;

import SBC.RamInformation;
import com.google.gson.JsonObject;
import lombok.Getter;
import lombok.Setter;

import java.util.Map;

import static code.common.gson;

@Getter
@Setter
public class SocketioResponse {
    private String response;
    private String data;

    public SocketioResponse(){
        response = "";
        data = "";
    }

    public SocketioResponse(String response, String data){
        this.response = response;
        this.data = data;
    }

    @Override
    public String toString(){
        return gson.toJson(this);
    }

    public static SocketioResponse fromLoginSetting(String response, LoginSetting loginSetting){
        SocketioResponse socketioResponse = new SocketioResponse();
        socketioResponse.setResponse(response);
        socketioResponse.setData(gson.toJson(loginSetting));
        return socketioResponse;
    }

    public static SocketioResponse fromSipSetting(String response, SipSetting sipSetting){
        SocketioResponse socketioResponse = new SocketioResponse();
        socketioResponse.setResponse(response);
        socketioResponse.setData(gson.toJson(sipSetting));
        return socketioResponse;
    }

    public static SocketioResponse fromRamInformation(String response, RamInformation ramInformation){
        SocketioResponse socketioResponse = new SocketioResponse();
        socketioResponse.setResponse(response);
        socketioResponse.setData(gson.toJson(ramInformation));
        return socketioResponse;
    }

    public static SocketioResponse fromCpuStatus(String response, int cpuTemperature, Map<String,Integer> cpuUsage){
        SocketioResponse socketioResponse = new SocketioResponse();
        socketioResponse.setResponse(response);
        JsonObject jo = new JsonObject();
        jo.addProperty("cpuTemperature", cpuTemperature);
        jo.addProperty("cpuUsage", gson.toJson(cpuUsage));
        socketioResponse.setData(jo.toString());
        return socketioResponse;
    }

    public static SocketioResponse fromTxRxMap(String response, Map<String,String> txmap, Map<String,String> rxmap){
        SocketioResponse socketioResponse = new SocketioResponse();
        socketioResponse.setResponse(response);
        JsonObject jo = new JsonObject();
        jo.addProperty("txmap", gson.toJson(txmap));
        jo.addProperty("rxmap", gson.toJson(rxmap));
        socketioResponse.setData(jo.toString());
        return socketioResponse;
    }


}
