const mongoose = require("mongoose");

const shiftSchema = new mongoose.Schema(
    {
        shiftName: {
            type: String,
            required: [true, "Shift name is required"],
            trim: true,
            minlength: [3, "Shift name must be at least 3 characters long"],
            maxlength: [50, "Shift name cannot exceed 50 characters"],
            match: [/^[A-Za-z\s]+$/, "Shift name must contain only letters and spaces"],
            index: true,
        },

        startTime: {
            type: String,
            required: [true, "Start time is required"],
            match: [
                /^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/,
                "Invalid time format. Use HH:MM (24-hour format)",
            ],
        },

        endTime: {
            type: String,
            required: [true, "End time is required"],
            match: [
                /^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/,
                "Invalid time format. Use HH:MM (24-hour format)",
            ],
        },

        orgId: {
            type: mongoose.Schema.Types.ObjectId,
            ref: "Organization",
            required: true,
            index: true,
        },

        // status: {
        //   type: String,
        //   enum: ["active", "inactive"],
        //   default: "active",
        // },

        isDeleted: {
            type: Boolean,
            default: false,
            index: true,
        },

        createdBy: {
            type: mongoose.Schema.Types.ObjectId,
            ref: "User",
            required: true,
            immutable: true,
        },

        updatedBy: {
            type: mongoose.Schema.Types.ObjectId,
            ref: "User",
            required: true,
        },

        lastActivity: {
            type: Date,
            default: Date.now,
        },
    },
    {
        timestamps: true,
    }
);

module.exports = mongoose.model("Shift", shiftSchema);
