const Leave = require("../models/leaveModel");


const getDoctorLeaveForDate = async (doctorId, date, orgId) => {
    const selectedDate = new Date(date);

    // Set to start of day (important)
    selectedDate.setHours(0, 0, 0, 0);

    const nextDay = new Date(selectedDate);
    nextDay.setDate(nextDay.getDate() + 1);

    return await Leave.findOne({
        employee: doctorId,
        orgId,
        isDeleted: false,
        status: "Approved",
        startDate: { $lt: nextDay },   // leave started before next day
        endDate: { $gte: selectedDate } // leave ends after start of day
    });
};
module.exports = {
    getDoctorLeaveForDate,
};
