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

interface IVolunteer {
  user_id: number;
  username: string;
  report_count: number;
  likes_given_count: number;
  likes_received_count: number;
  average_rating: number;
}

interface IVolunteerStore extends IFetch {
  data: IVolunteer[];
  getVolunteers: () => Promise<void>;
}

export const useVolunteers = create<IVolunteerStore>((set) => ({
  data: [],
  loading: false,
  error: "",
  getVolunteers: async () => {
    try {
      set({ loading: true });

      const response = await axios.get<IVolunteer[]>(
        `${baseAPI}/report/user_ratings/`
      );

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