import { apiFetch } from "./auth";

export type GameMode = "survival" | "creative" | "adventure" | "spectator";
export type Difficulty = "peaceful" | "easy" | "normal" | "hard";

export interface ServerProperties {
  motd: string;
  gamemode: GameMode;
  difficulty: Difficulty;
  maxPlayers: number;
  pvp: boolean;
  whitelist: boolean;
  hardcore?: boolean;
  onlineMode?: boolean;
  enableCommandBlock?: boolean;
  viewDistance?: number;
  simulationDistance?: number;
  spawnProtection?: number;
  allowFlight?: boolean;
}

export type UpdateServerPropertiesPayload = Partial<ServerProperties>;

export async function getProperties(serverId: string): Promise<ServerProperties> {
  return apiFetch<ServerProperties>(`/servers/${serverId}/properties`);
}

export async function updateProperties(
  serverId: string,
  payload: UpdateServerPropertiesPayload,
): Promise<ServerProperties> {
  return apiFetch<ServerProperties>(`/servers/${serverId}/properties`, {
    method: "PATCH",
    body: JSON.stringify(payload),
  });
}
