"use client";

import makeContext from "@/lib/contextFactory/contextFactory";
import {
    ServiceCategoriesCrud,
    useServiceCategoriesCrud,
} from "@/modules/dealModularEditorTabs/FulfillmentBase/shared/hooks/cruds/useServiceCategoriesCrud";
import {
    ServicesCrud,
    useServicesCrud,
} from "@/modules/dealModularEditorTabs/FulfillmentBase/shared/hooks/cruds/useServicesCrud";
import {
    ServicesKitsCrud,
    useServicesKitsCrud,
} from "@/modules/dealModularEditorTabs/FulfillmentBase/shared/hooks/cruds/useServicesKitsCrud";
import useServiceCategoriesList, {
    ServiceCategoriesList,
} from "@/modules/dealModularEditorTabs/FulfillmentBase/shared/hooks/lists/useServiceCategoriesList";
import useServicesKitsList, {
    ServicesKitsList,
} from "@/modules/dealModularEditorTabs/FulfillmentBase/shared/hooks/lists/useServicesKitsList";
import useServicesList, {
    ServicesList,
} from "@/modules/dealModularEditorTabs/FulfillmentBase/shared/hooks/lists/useServicesList";

type ServicesContextState = {
    servicesList: ServicesList;
    servicesCrud: ServicesCrud;
    servicesKitList: ServicesKitsList;
    servicesKitCrud: ServicesKitsCrud;
    categoriesList: ServiceCategoriesList;
    categoriesCrud: ServiceCategoriesCrud;
};

const useFulfillmentBaseContextState = (): ServicesContextState => {
    const servicesList = useServicesList();
    const servicesCrud = useServicesCrud(servicesList);

    const servicesKitList = useServicesKitsList();
    const servicesKitCrud = useServicesKitsCrud(servicesKitList);

    const categoriesList = useServiceCategoriesList();
    const categoriesCrud = useServiceCategoriesCrud(categoriesList);

    return {
        servicesList,
        servicesCrud,
        servicesKitList,
        servicesKitCrud,
        categoriesList,
        categoriesCrud,
    };
};

export const [ServicesContextProvider, useServicesContext] =
    makeContext<ServicesContextState>(
        useFulfillmentBaseContextState,
        "Services"
    );
