import { baseAPI } from "@/shared/api/baseAPI";
import axios, { AxiosError } from "axios";

interface IStatsCount {
  category: number;
  count: number;
}

export const statiscsSectionStore = () => {
  let errorMessage = "";
  async function getStatsCount() {
    try {
      const response = await axios.get<IStatsCount[]>(
        `${baseAPI}/report/category_count/`
      );

      return response.data;
    } catch (error: unknown) {
      if (error instanceof AxiosError) {
        errorMessage = error.message;
      } else {
        errorMessage = "An error ocured";
      }
    }
  }

  function getErrorMessage() {
    return errorMessage;
  }

  return {
    getStatsCount,
    getErrorMessage,
  };
};
