import EntityManager from "~/services/data/entityManager";
import {useAp2iRequestService} from "~/composables/data/useAp2iRequestService";
import ApiResource from "~/models/ApiResource";
import {useRepo} from "pinia-orm";

let entityManager:EntityManager|null = null

export const useEntityManager = () => {
    //Avoid memory leak
    if(entityManager === null){
        const { apiRequestService } = useAp2iRequestService()
        const getRepo = (model: typeof ApiResource) => useRepo(model)

        entityManager = new EntityManager(apiRequestService, getRepo)
    }
    return { em: entityManager }
}
