import { baseAPI } from "@/Shared/API/baseAPI";
import { IFetch } from "@/Shared/types";
import axios from "axios";
import { create } from "zustand";
import { ILocation, IReport } from "./types";

interface IMapStore extends IFetch {
  data: IReport;
  getRatings: (categories: string) => Promise<void>;
}

export const useMapStore = create<IMapStore>((set) => ({
  data: {
    count: 0,
    previous: null,
    next: null,
    results: [],
  },
  loading: false,
  error: "",
  getRatings: async (
    categories: string = "1,2,3,4,5,6",
    query: string = ""
  ) => {
    try {
      set({ loading: true });

      const response = await axios.get<IReport>(
        `${baseAPI}/report/?category=${categories}`
      );

      set({ data: response.data });
    } catch (error: any) {
      set({ error: error.message });
    } finally {
      set({ loading: false });
    }
  },
}));
