const mongoose = require('mongoose');

const modelSchema = new mongoose.Schema({
    brandName: {
        type: mongoose.Schema.Types.ObjectId,
        ref: "VehicleBrand",
        required: [true, "Brand is required"]
    },
    category: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'VehicleCategory',
        required: [true, 'Vehicle Category is required'],
        index: true
    },
    modelName: {
        type: String,
        required: [true, "Model name is required"],
        trim: true
    },
    group: {
        type: mongoose.Schema.Types.ObjectId,
        ref: "VehicleGroup",
        required: [true, "Group is required"]
    },
    acAvailable: {
        type: Boolean,
        default: true
    },
    vehicleImages: {
        type: [
            {
                view: {
                    type: String,
                    // enum: ['front', 'back', 'left', 'right'],
                    required: [true, 'view angle type is required']
                },
                url: {
                    type: String,
                    required: [true, "image url is required"]
                }
            }
        ],
        validate: {
            validator: function (value) {
                return value.length >= 2;   // minimum 3 images
            },
            message: "At least 2 vehicle images are required."
        }
    },
    createdBy: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User'
    },
    status: {
        type: String,
        enum: ['active', 'inactive'],
        default: 'active',
        index: true
    }
}, { timestamps: true });

module.exports = mongoose.model('VehicleModel', modelSchema);
