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

module.exports = (sequelize) => {
  const DocumentGroup = sequelize.define(
    "documentgroup",
    {
      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 },

      // fk
      company_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
      },
  
    },
    {
      tableName: "documentgroups",
      freezeTableName: true,
    }
  );

  /**
   * Associates the DoucmentGroup model with other models.
   * @param {object} models - The models to associate with.
   */
  DocumentGroup.associate = (models) => {
    DocumentGroup.belongsTo(models.Company, { foreignKey: "company_id", as: "company" });
    DocumentGroup.hasMany(models.DMSRegulatory, { foreignKey: "documentgroup_id", as: "dmsregulatories" });
  };

  return DocumentGroup;
};
