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

allocation_role: {
        type: DataTypes.ENUM,
      
      

        values: [

"primary",


"cascade_parent",


"cascade_child",


"backup"

        ],

      },

allocated_at: {
        type: DataTypes.DATE,
      
      

      },

released_at: {
        type: DataTypes.DATE,
      
      

      },

allocation_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"allocated",


"migrating",


"released",


"failed"

        ],

      },

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

  sfu_allocations.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.sfu_allocations.belongsTo(db.conferences, {
      as: 'conference',
      foreignKey: {
        name: 'conferenceId',
      },
      constraints: false,
    });

    db.sfu_allocations.belongsTo(db.conference_nodes, {
      as: 'conference_node',
      foreignKey: {
        name: 'conference_nodeId',
      },
      constraints: false,
    });

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




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

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



  return sfu_allocations;
};


