const mongoose = require("mongoose");


const leaveSchema = new mongoose.Schema({
    employee: {
        type: mongoose.Schema.Types.ObjectId,
        ref: "User",
        required: true
    },
    leaveType: {
        type: String,
        trim: true,
        enum: ["Annual", "Sick", "Casual", "Unpaid", "Other"],
        required: true,
    },
    startDate: {
        type: Date,
        required: true,
    },

    endDate: {
        type: Date,
        required: true,
    },
    isHalfDay: {
        type: Boolean,
        default: false,
    },

    reason: {
        type: String,
        trim: true,
        maxlength: 500,
    },
    approvedBy: {
        type: mongoose.Schema.Types.ObjectId,
        ref: "User",
        default: null,
    },

    status: {
        type: String,
        enum: ["Pending", "Approved", "Rejected", "Cancelled"],
        default: "Pending",
    },
    appliedBy: {
        type: mongoose.Schema.Types.ObjectId,
        ref: "User",

    },
    appliedAt: {
        type: Date,
        default: Date.now,
    },

    approvedAt: {
        type: Date,
        default: null,
    },

    rejecrtedAt: {
        type: Date,
        default: null,
    },
    rejectedReason: {
        type: String,
        trim: true,
        maxlength: 500,
    },
    orgId: {
        type: mongoose.Schema.Types.ObjectId,
        ref: "Organization",
        required: true,
    },

    isDeleted: {
        type: Boolean,
        default: false,
    },
}
    , { timestamps: true }
)

module.exports = mongoose.model("Leave", leaveSchema);

