// models/admin/variantModel.js
const mongoose = require("mongoose");

const variantSchema = new mongoose.Schema(
    {
        variantName: {
            type: String,
            required: [true, "Variant name is required"],
            trim: true,
            minlength: [2, "Variant name must be at least 2 characters long"],
            maxlength: [150, "Variant name cannot exceed 150 characters"],
        },
        values: {
            type: [String],
            required: [true, "Variant values are required"],
            validate: {
                validator: (arr) => arr.length > 0,
                message: "There must be at least one variant value",
            },
        },
        orgId: {
            type: mongoose.Schema.Types.ObjectId,
            ref: "Organization",
            required: [true, "Organization ID is required"],
        },
        status: {
            type: Boolean,
            default: true, // active by default
        },
        isDeleted: {
            type: Boolean,
            default: false, // soft delete
        },
        createdBy: {
            type: mongoose.Schema.Types.ObjectId,
            ref: "User",
            required: true,
        },
        updatedBy: {
            type: mongoose.Schema.Types.ObjectId,
            ref: "User",
            required: true,
        },
    },
    {
        timestamps: true,
    }
);

module.exports = mongoose.model("Variant", variantSchema);
