import { ProjectSchema } from "../../client";

export enum Modules {
    SERVICES_AND_PRODUCTS = "servicesAndProducts",
    SHIPMENT = "shipment",
    EMPLOYEES = "employees",
    CLIENTS = "clients",
    MANAGERS = "managers",
}

const isModuleInProject = (module: Modules, project?: ProjectSchema | null) => {
    // if servicesAndProducts included, then clients also included
    if (module === Modules.CLIENTS) {
        if (project?.modules.findIndex(m => m.key === Modules.SERVICES_AND_PRODUCTS.toString()) !== -1) {
            return true;
        }
    }

    return project?.modules.findIndex(m => m.key === module.toString()) !== -1;
};

export default isModuleInProject;
