"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get createAppointment () {
        return createAppointment;
    },
    get createRepeatingAppointment () {
        return createRepeatingAppointment;
    }
});
const _lodash = require("lodash");
const _constants = require("@tamanu/constants");
const _utilities = require("@tamanu/database/demoData/utilities");
const _index = require("../../fake/index.js");
const createAppointment = async ({ models, locationGroupId, patientId, clinicianId })=>{
    const { Appointment } = models;
    await Appointment.create((0, _index.fake)(Appointment, {
        patientId: patientId || await (0, _utilities.randomRecordId)(models, 'Patient'),
        clinicianId: clinicianId || await (0, _utilities.randomRecordId)(models, 'User'),
        locationGroupId: locationGroupId || await (0, _utilities.randomRecordId)(models, 'LocationGroup')
    }));
};
const createRepeatingAppointment = async ({ models, limit, locationGroupId, patientId, clinicianId, apptCount = _index.chance.integer({
    min: 1,
    max: 50
}) })=>{
    const { AppointmentSchedule, Appointment } = models;
    const appointmentSchedule = await AppointmentSchedule.create((0, _index.fake)(AppointmentSchedule, {
        frequency: _constants.REPEAT_FREQUENCY.WEEKLY,
        locationGroupId: locationGroupId ?? await (0, _utilities.randomRecordId)(models, 'LocationGroup')
    }));
    await Promise.all((0, _lodash.times)(apptCount, ()=>limit(async ()=>{
            await Appointment.create((0, _index.fake)(Appointment, {
                patientId: patientId ?? await (0, _utilities.randomRecordId)(models, 'Patient'),
                clinicianId: clinicianId ?? await (0, _utilities.randomRecordId)(models, 'User'),
                locationGroupId: locationGroupId ?? await (0, _utilities.randomRecordId)(models, 'LocationGroup'),
                scheduleId: appointmentSchedule.id
            }));
        })));
};

//# sourceMappingURL=appointment.js.map