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

name: {
        type: DataTypes.TEXT,
      
      

      },

tool_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"fishing_rod",


"axe",


"pickaxe",


"hoe",


"watering_can",


"knife",


"hammer",


"net",


"boat",


"vehicle"

        ],

      },

tier: {
        type: DataTypes.ENUM,
      
      

        values: [

"basic",


"copper",


"iron",


"steel",


"gold",


"legendary"

        ],

      },

durability_max: {
        type: DataTypes.DECIMAL,
      
      

      },

durability_current: {
        type: DataTypes.DECIMAL,
      
      

      },

repair_cost: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  tools.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.tools.hasMany(db.file, {
      as: 'tool_images',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.tools.getTableName(),
        belongsToColumn: 'tool_images',
      },
    });


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

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



  return tools;
};


