// src/services/categoryService.ts
import apiClient from '@/services/axiosSetup';
import {Category} from "@/models/Category";
import {useSpaceStore} from "@/stores/spaceStore";  // Импортируете настроенный экземпляр axios

export const getCategories = async (type = null) => {
    const spaceStore = await useSpaceStore();

    const params = {};
    if (type) {
        params.type = type;
    }
    return await apiClient.get(`/spaces/${spaceStore.space?.id}/categories`, {
        params: params
    });
};

export const getCategoryTypes = async () => {
    const spaceStore = useSpaceStore();
    return await apiClient.get(`/spaces/${spaceStore.space?.id}/categories/types`);
}

export const createCategory = async (category: Category) => {
    const spaceStore = useSpaceStore();
    return await apiClient.post(`/spaces/${spaceStore.space?.id}/categories`, category);
};

export const updateCategory = async (id: number, category: any) => {
    const spaceStore = useSpaceStore();
    return await apiClient.put(`/spaces/${spaceStore.space?.id}/categories/${id}`, category);
};

export const deleteCategory = async (id: number) => {
    const spaceStore = useSpaceStore();
    return await apiClient.delete(`/spaces/${spaceStore.space?.id}/categories/${id}`);
};

export const getCategoriesSumsRequest = async (spaceId: string) => {
    const spaceStore = useSpaceStore();
    return await apiClient.get(`/spaces/${spaceStore.space?.id}/analytics/by-month`)

}
