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

concept: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"collecting_requirements",


"draft_ready",


"published",


"cancelled"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

finished_at: {
        type: DataTypes.DATE,
      
      

      },

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

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

    db.community_mode_build_sessions.belongsTo(db.community_modes, {
      as: 'result_mode',
      foreignKey: {
        name: 'result_modeId',
      },
      constraints: false,
    });




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

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



  return community_mode_build_sessions;
};


