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

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

      date:{type: DataTypes.DATE, allowNull: true},
      expired_date:{type: DataTypes.DATE, allowNull: true},
      reminder_day:{type: DataTypes.INTEGER, allowNull: true},
      notification_date:{type: DataTypes.DATE, allowNull: true},
      issue_date:{type: DataTypes.DATE, allowNull: true},
      document_number:{type: DataTypes.STRING, allowNull: true},
      document_1:{type: DataTypes.TEXT, allowNull: true},
      document_2:{type: DataTypes.TEXT, allowNull: true},
      document_3:{type: DataTypes.TEXT, allowNull: true},
      document_type:{type: DataTypes.JSON, allowNull: true},
      team:{ type: DataTypes.JSON, allowNull: true },
      team_permission:{ type: DataTypes.JSON, allowNull: true },
      user_info:{ type: DataTypes.JSON, allowNull: true },
      is_private:{type: DataTypes.BOOLEAN, allowNull: true},
      
      nie:{type: DataTypes.STRING, allowNull: true},
      history_desc:{type: DataTypes.STRING, allowNull: true},
      history_desc2:{type: DataTypes.STRING, allowNull: true},
      history_desc3:{type: DataTypes.STRING, allowNull: true},
      history_desc4:{type: DataTypes.STRING, allowNull: true},
      history_desc5:{type: DataTypes.STRING, allowNull: true},

      history_date:{type: DataTypes.DATEONLY, allowNull: true},
      history_date2:{type: DataTypes.DATEONLY, allowNull: true},
      history_date3:{type: DataTypes.DATEONLY, allowNull: true},
      history_date4:{type: DataTypes.DATEONLY, allowNull: true},
      history_date5:{type: DataTypes.DATEONLY, allowNull: true},

      history_doc:{type: DataTypes.TEXT, allowNull: true},
      history_doc2:{type: DataTypes.TEXT, allowNull: true},
      history_doc3:{type: DataTypes.TEXT, allowNull: true},
      history_doc4:{type: DataTypes.TEXT, allowNull: true},
      history_doc5:{type: DataTypes.TEXT, allowNull: true},

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

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

  return DMSRegulatory;
};
