const { DataTypes } = require('sequelize'); const sequelize = require('../config/database'); const Menu = sequelize.define('Menu', { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, nom: { type: DataTypes.STRING(255), allowNull: false, validate: { notEmpty: { msg: 'Le nom du plat est requis' }, len: { args: [2, 255], msg: 'Le nom doit contenir entre 2 et 255 caractères' } } }, commentaire: { type: DataTypes.TEXT, allowNull: true, validate: { len: { args: [0, 1000], msg: 'Le commentaire ne doit pas dépasser 1000 caractères' } } }, prix: { type: DataTypes.DECIMAL(10, 2), allowNull: false, validate: { isDecimal: { msg: 'Le prix doit être un nombre décimal' }, min: { args: [0], msg: 'Le prix doit être positif' } } }, categorie_id: { type: DataTypes.INTEGER, allowNull: false, validate: { isInt: { msg: 'L\'ID de catégorie doit être un entier' }, min: { args: [1], msg: 'L\'ID de catégorie doit être positif' } } }, disponible: { type: DataTypes.BOOLEAN, defaultValue: true, allowNull: false }, image_url: { type: DataTypes.STRING(500), allowNull: true, validate: { isUrl: { msg: 'L\'URL de l\'image doit être valide' } } }, ingredients: { type: DataTypes.TEXT, allowNull: true }, allergenes: { type: DataTypes.STRING(500), allowNull: true }, calories: { type: DataTypes.INTEGER, allowNull: true, validate: { min: { args: [0], msg: 'Les calories doivent être positives' } } }, temps_preparation: { type: DataTypes.INTEGER, allowNull: true, validate: { min: { args: [1], msg: 'Le temps de préparation doit être positif' } } } }, { tableName: 'menus', timestamps: true, createdAt: 'created_at', updatedAt: 'updated_at' }); module.exports = Menu;