const { DataTypes } = require("sequelize");

module.exports = (sequelize) => {
  const OutletType = sequelize.define(
    "outlettype",
    {
      id: {
        type: DataTypes.INTEGER,
        autoIncrement: true,
        primaryKey: true,
      },
      creation: { type: DataTypes.DATE, allowNull: false },
      modified: { type: DataTypes.DATE, allowNull: false },
      modified_by: { type: DataTypes.INTEGER, allowNull: false },
      owner: { type: DataTypes.INTEGER, allowNull: false },
      enabled: { type: DataTypes.BOOLEAN, allowNull: false },

      display_name: { type: DataTypes.STRING(100), allowNull: false },
      code: { type: DataTypes.STRING(10), allowNull: true },
      slug: { type: DataTypes.STRING(10), allowNull: true },
      population: { type: DataTypes.STRING(100), allowNull: true },
    },
    {
      tableName: "outlettypes",
      freezeTableName: true,
    }
  );

  /**
   * Associates the OutletType model with other models.
   * @param {object} models - The models to associate with.
   */
  OutletType.associate = function (models) {
    /**
     * Associates the OutletType model with the Outlet model.
     * Defines a one-to-many relationship between OutletType and Outlet.
     * @param {object} models - The models to associate with.
     */
    OutletType.hasMany(models.Outlet, { foreignKey: "outlettype_id", as: "outlettypes" });
  };

  return OutletType;
};
