const mongoose = require('mongoose');

const productSchema = new mongoose.Schema(
    {
        title: {
            type: String,
            required: true,
            trim: true,
        },

        categoryId: {
            type: mongoose.Schema.Types.ObjectId,
            ref: 'category',
            required: true, // danh mục con
        },

        price: {
            type: Number,
            required: true,
        },

        images: [String],

        description: {
            type: String,
        },

        account: {
            username: { type: String, required: true },
            password: { type: String, required: true },
        },
        info: { type: mongoose.Schema.Types.Mixed, default: {} },

        // Trạng thái bán
        status: {
            type: String,
            enum: ['available', 'sold', 'locked'],
            default: 'available',
        },
    },
    { timestamps: true },
);

module.exports = mongoose.model('Product', productSchema);
