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 contract_amendments = sequelize.define(
    'contract_amendments',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

amendment_number: {
        type: DataTypes.TEXT,
      
      

      },

amendment_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"value_change",


"time_extension",


"scope_change",


"administrative",


"other"

        ],

      },

value_change_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

days_extension: {
        type: DataTypes.INTEGER,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"submitted",


"approved",


"rejected",


"implemented"

        ],

      },

effective_date: {
        type: DataTypes.DATE,
      
      

      },

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

  contract_amendments.associate = (db) => {


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




















































//end loop



    db.contract_amendments.belongsTo(db.contracts, {
      as: 'contract',
      foreignKey: {
        name: 'contractId',
      },
      constraints: false,
    });

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




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

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



  return contract_amendments;
};


