import { queryBanzones } from "@/controller/MapController";
import { create } from "zustand";

type Banzone = {
  banzones: Model.Zone[];
  getBanzone: () => Promise<void>;
  error: string | null;
  loading?: boolean;
};

export const useBanzones = create<Banzone>()((set) => ({
  banzones: [],
  getBanzone: async () => {
    set({ loading: true });
    try {
      const response = await queryBanzones();
      console.log("Banzone fetching: ", response.data.length);

      set({ banzones: response.data, loading: false });
    } catch (error) {
      console.error("Error when fetch Banzones: ", error);
      set({ error: "Failed to fetch banzone data", loading: false });
      set({ banzones: [] });
    }
  },
  error: null,
}));
