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

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

      name: { type: DataTypes.STRING(100), allowNull: false },
      document_number: { type: DataTypes.STRING(250), allowNull: true },
      registration_number: { type: DataTypes.STRING(250), allowNull: true },
      counter_part: { type: DataTypes.STRING(100), allowNull: true },
      date: { type: DataTypes.DATE, allowNull: true },
      exp_date: { type: DataTypes.DATE, allowNull: true },
      original: { type: DataTypes.STRING(50), allowNull: true },
      copy: { type: DataTypes.STRING(50), allowNull: true },
      status: { type: DataTypes.STRING(50), allowNull: true },
      class: { type: DataTypes.STRING(50), allowNull: true },
      owner_doc: { type: DataTypes.STRING(50), allowNull: true },
      remark: { type: DataTypes.STRING(50), allowNull: true },
      softfile: { type: DataTypes.STRING(1000), allowNull: true },
      
      //fk
      dmslegal_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
          model: "dmslegals",
          key: "id",
        },
      },

    },
    {
      tableName: "dmslegalchilds",
      freezeTableName: true,
    }
  );

  /**
   * Associates the DMSLegalChild model with other models.
   * @param {object} models - The models to associate with.
   * @description
   *   - A DMSLegalChild belongs to a DMSLegal.
   */
  DMSLegalChild.associate = (models) => {
    /**
     * Associates the DMSLegalChild model with the DMSLegal model.
     * A DMSLegalChild belongs to a DMSLegal.
     * @param {object} models - The models to associate with.
     */
   DMSLegalChild.belongsTo(models.DMSLegal, {
      foreignKey: "dmslegal_id",
      as: "dmslegal",
    });
  };

  return DMSLegalChild;
};
