import CfExceptionHandler from "../../../core/CfExceptionHandler";
import {checkObjectFieldEmptyiness} from "../../../utils";
import {injectCatalog} from "../../../core/injector";
import {HcwCatalogModel, PatientCatalogModel, PatientMgmtCatalogType} from "../typings";

export async function validateAndSaveHCWCatalog(hcwId: string, properties: HcwCatalogModel) {

    if (!hcwId) {
        new CfExceptionHandler().throwAndLogError(
            "hcw catalog",
            "invalid hcw catalog id"
        );
    }
    checkObjectFieldEmptyiness(properties, [
        "services_list",
        "site_ids_list",
        "role_permissions_list",
    ]);
    injectCatalog(hcwId, PatientMgmtCatalogType.UserHcw, properties);
}

export async function validateAndSavePatientCatalog(patientId: string, properties: PatientCatalogModel) {

    if (!patientId) {
        new CfExceptionHandler().throwAndLogError(
            "patient catalog",
            "invalid patient catalog id"
        );
    }
    checkObjectFieldEmptyiness(properties, [
        "country",
        "education_level",
        "site_id_list",
    ]);
    injectCatalog(patientId, PatientMgmtCatalogType.Patient, properties);
}
