const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');

module.exports = function(sequelize, DataTypes) {
  const notification_records = sequelize.define(
    'notification_records',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"in_test",


"approved",


"locked"

        ],

      },

approved_at: {
        type: DataTypes.DATE,
      
      

      },

record_hash: {
        type: DataTypes.TEXT,
      
      

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  notification_records.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
































    db.notification_records.hasMany(db.notification_record_items, {
      as: 'notification_record_items_notification_record',
      foreignKey: {
          name: 'notification_recordId',
      },
      constraints: false,
    });













//end loop



    db.notification_records.belongsTo(db.contract_folders, {
      as: 'contract_folder',
      foreignKey: {
        name: 'contract_folderId',
      },
      constraints: false,
    });

    db.notification_records.belongsTo(db.contract_participants, {
      as: 'contract_participant',
      foreignKey: {
        name: 'contract_participantId',
      },
      constraints: false,
    });

    db.notification_records.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });



    db.notification_records.hasMany(db.file, {
      as: 'record_pdf',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.notification_records.getTableName(),
        belongsToColumn: 'record_pdf',
      },
    });


    db.notification_records.belongsTo(db.users, {
      as: 'createdBy',
    });

    db.notification_records.belongsTo(db.users, {
      as: 'updatedBy',
    });
  };



  return notification_records;
};


