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

objective_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"deliver_item",


"collect_item",


"talk_to_npc",


"visit_location",


"catch_fish",


"harvest_crop",


"craft_item",


"build_upgrade",


"sell_item",


"buy_item"

        ],

      },

target_quantity: {
        type: DataTypes.INTEGER,
      
      

      },

sequence_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  quest_objectives.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.quest_objectives.belongsTo(db.quests, {
      as: 'quest',
      foreignKey: {
        name: 'questId',
      },
      constraints: false,
    });

    db.quest_objectives.belongsTo(db.items, {
      as: 'target_item',
      foreignKey: {
        name: 'target_itemId',
      },
      constraints: false,
    });

    db.quest_objectives.belongsTo(db.npcs, {
      as: 'target_npc',
      foreignKey: {
        name: 'target_npcId',
      },
      constraints: false,
    });

    db.quest_objectives.belongsTo(db.locations, {
      as: 'target_location',
      foreignKey: {
        name: 'target_locationId',
      },
      constraints: false,
    });




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

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



  return quest_objectives;
};


