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

file_path: {
        type: DataTypes.TEXT,
      
      

      },

change_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"create",


"update",


"delete",


"rename"

        ],

      },

diff_text: {
        type: DataTypes.TEXT,
      
      

      },

applied_successfully: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

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

  code_patches.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.code_patches.belongsTo(db.code_change_sets, {
      as: 'change_set',
      foreignKey: {
        name: 'change_setId',
      },
      constraints: false,
    });

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




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

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



  return code_patches;
};


