
import { requestClient } from '#/api/request';

export interface AppData {
  AppId : number;
  AppName : string;
  WsHost? : string;
  NodeName?: string;
  MysqlName?: string;
  Topic?: string;
  tz?: string;
  Status?: string;
  Update?:number;
  Loading?:boolean;
}

export interface ServerData {
  AppId : number;
  ServerId: number;
  ServerName: string;
  Status?: number;
  OpenServerTime?: number;
  StartTime?: number;
  PlayerNum?: number;
  Loading?:boolean;
  Reload?:boolean;
  CpuUsage?: number;
  MemUsage?: number;
  ClientVersion?: string;
  Tags?: string[];
  Latency?: number;
}

export interface editServerParam {
  AppId : number;
  ServerId: number;
  ServerName: string;
  Tags?: string;
  ClientVersion?: string;
}

export interface NodeData{
  NodeId?: number;
  NodeName: string;
  NodeIp: string;
  NodeInternalIp: string;
  NodeHardware: string;
  NodeArea: string;
  NodeOperator: string;
  NodeStatus?: number;
  NodeUser?: string;
  NodePassword?: string;
  NodeTz?: string;
}

export interface serverParam {
  AppId: number;
  Type?: number;
}

export async function getAppListApi(){
  return requestClient.post<AppData[]>('/server/list');
}

export async function getNodeListApi(){
  return requestClient.post<NodeData[]>('/server/nodeList');
}

export async function addNode(n :NodeData){
  return requestClient.post('/server/addNode', n);
}

export async function getServerListApi(P: serverParam){
  return requestClient.post<ServerData[]>('/server/serverList', P, {timeout: 120000});
}

export async function updateAppApi(AppId: number){
  return requestClient.post('/server/updateApp', {AppId: AppId}, {timeout: 120000});
}

export async function updateAppReviewApi(AppId: number){
  return requestClient.post('/server/updateAppReview', {AppId: AppId}, {timeout: 120000});
}

export async function releaseApp(appId: number, appName: string){
  return requestClient.post(`/server/release`, {AppId: appId, AppName: appName}, {timeout: 120000});
}

export async function restartServer(appId: number, serverId: number, serverName: string){
  return requestClient.post(`/server/restart`, {AppId: appId, ServerId: serverId, ServerName: serverName}, {timeout: 120000});
}

export async function reloadServer(appId: number, serverId: number, serverName: string){
  return requestClient.post(`/server/reload`, {AppId: appId, ServerId: serverId, ServerName: serverName}, {timeout: 120000});
}

export async function addServer(AppId:number, ServerId:number, ServerName: string, Status: number, OpenServerTime: number, Host?: string, Port?: number, WsPort?: number, Version?: string, Ecs?: number, WorkDir?: string){
  return requestClient.post(`/server/addServer`, {AppId:AppId, ServerId: ServerId, ServerName: ServerName, Status: Status, OpenServerTime: OpenServerTime, Host: Host, Port: Port, WsPort: WsPort, ClientVersion: Version, Ecs: Ecs, WorkDir: WorkDir});
}

export async function editServer(editParam: editServerParam){
  return requestClient.post(`/server/editServer`, editParam);
}

