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

title: {
        type: DataTypes.TEXT,
      
      

      },

event_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"weather",


"tourism",


"economy",


"market",


"npc",


"environment"

        ],

      },

severity: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"medium",


"high",


"critical"

        ],

      },

starts_at: {
        type: DataTypes.DATE,
      
      

      },

ends_at: {
        type: DataTypes.DATE,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  random_events.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.random_events.belongsTo(db.world_regions, {
      as: 'region',
      foreignKey: {
        name: 'regionId',
      },
      constraints: false,
    });




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

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



  return random_events;
};


