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

name: {
        type: DataTypes.TEXT,
      
      

      },

region_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"village_center",


"market",


"home_area",


"harbor",


"beach",


"forest",


"mangrove",


"farm",


"fishing_area",


"mountain",


"tourist_area",


"bakery",


"school",


"church",


"town_square",


"cave",


"secret_location"

        ],

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

latitude: {
        type: DataTypes.DECIMAL,
      
      

      },

longitude: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

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

  world_regions.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity






    db.world_regions.hasMany(db.locations, {
      as: 'locations_region',
      foreignKey: {
          name: 'regionId',
      },
      constraints: false,
    });












































    db.world_regions.hasMany(db.random_events, {
      as: 'random_events_region',
      foreignKey: {
          name: 'regionId',
      },
      constraints: false,
    });



//end loop





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


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

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



  return world_regions;
};


