const ADDRESS = "http://127.0.0.1:65000";

type Instance = {
  name: string;
  version: string;
  port: number;
  status: string;
};

class api {
    
 
} export default api;

export async function fetchInstanceList(): Promise<Instance[]> {
    const res = await fetch(`${ADDRESS}/instances/list`);
    if (!res.ok) throw new Error(`Could not fetch instance list: ${res.status}`);
    return res.json();
}

export async function sendStartInstanceRequest(name: string) {
    const res = await fetch(`${ADDRESS}/instances/start?name=${name}`, {method: "POST"});
    if (!res.ok) throw new Error(`Start Server Request failed: ${res.status}`);
    return res.json;
}

export async function sendStopInstanceRequest(name: string) {
    const res = await fetch(`${ADDRESS}/instances/stop?name=${name}`, {method: "POST"});
    if (!res.ok) throw new Error(`Stop Server Request failed: ${res.status}`);
    return res.json;
}