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

service_name: {
        type: DataTypes.TEXT,
      
      

      },

git_ref: {
        type: DataTypes.TEXT,
      
      

      },

change_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"deploy",


"rollback",


"config_change",


"feature_flag"

        ],

      },

rollout_stage: {
        type: DataTypes.ENUM,
      
      

        values: [

"shadow",


"canary",


"stable",


"aborted"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

diff_summary: {
        type: DataTypes.TEXT,
      
      

      },

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

  deployment_changes.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.deployment_changes.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return deployment_changes;
};


