// models/MenuItem.js
const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
  const MenuItem = sequelize.define('MenuItem', {
    name: {
      type: DataTypes.STRING,
      allowNull: false
    },
    link: {
      type: DataTypes.STRING,
      allowNull: false
    },
    component: {
      type: DataTypes.STRING,
      allowNull: false
    },
    show_in_menu: {
      type: DataTypes.BOOLEAN,
      allowNull: false,
      defaultValue: true
    },
    requires_auth: {
      type: DataTypes.BOOLEAN,
      allowNull: false,
      defaultValue: false
    },
    parent_id: {
      type: DataTypes.INTEGER,
      allowNull: true
    },
    order_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0
    },
    page_title: {
      type: DataTypes.STRING,
      allowNull: true
    },
    image: {
      type: DataTypes.STRING,
      allowNull: true,
    },
  }, {
    tableName: 'menu_items',
    timestamps: false
  });

  MenuItem.associate = function(models) {
    MenuItem.hasMany(models.MenuItem, {
      foreignKey: 'parent_id',
      as: 'submenu'
    });
  };

  return MenuItem;
};
