import { create } from "zustand";

type ServerVersion = {
	packageName: string;
	versionName: string;
	versionCode: number;
	minSupportedVersionCode: number;
	downloadUrl: string;
};

type AppState = {
	serverVersion: ServerVersion | null;

	setServerVersion: (data: ServerVersion) => void;
};

export const useServerStore = create<AppState>((set, get) => ({
	serverVersion: null,
	hasUpdate: () => {
		const v = get().serverVersion;
		if (!v) return false;

		return v.versionCode < v.minSupportedVersionCode;
	},
	setServerVersion: (data) =>
		set(() => ({
			serverVersion: data,
		})),
}));
