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

review_title: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"scheduled",


"in_progress",


"completed",


"archived"

        ],

      },

meeting_start_at: {
        type: DataTypes.DATE,
      
      

      },

meeting_end_at: {
        type: DataTypes.DATE,
      
      

      },

agenda: {
        type: DataTypes.TEXT,
      
      

      },

minutes: {
        type: DataTypes.TEXT,
      
      

      },

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

  management_reviews.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.management_reviews.belongsTo(db.users, {
      as: 'chairperson',
      foreignKey: {
        name: 'chairpersonId',
      },
      constraints: false,
    });



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


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

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



  return management_reviews;
};


