const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

module.exports = (sequelize) => {
const CommandeItem = sequelize.define('CommandeItem', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    commande_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: 'commandes',
            key: 'id'
        }
    },
    menu_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: 'menus',
            key: 'id'
        }
    },
    quantite: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 1,
        validate: {
            min: {
                args: [1],
                msg: 'La quantité doit être au moins de 1'
            }
        }
    },
    prix_unitaire: {
        type: DataTypes.DECIMAL(10, 2),
        allowNull: false
    },
    total_item: {
        type: DataTypes.DECIMAL(10, 2),
        allowNull: false
    },
    commentaires: {
        type: DataTypes.TEXT,
        allowNull: true
    },
    statut: {
        type: DataTypes.ENUM('commande', 'en_preparation', 'pret', 'servi'),
        defaultValue: 'commande'
    }
}, {
    tableName: 'commande_items',
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at'
});
return CommandeItem;
}
