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

name: {
        type: DataTypes.TEXT,
      
      

      },

recipe_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"food",


"furniture",


"decoration",


"tool",


"equipment"

        ],

      },

output_quantity: {
        type: DataTypes.INTEGER,
      
      

      },

craft_time_seconds: {
        type: DataTypes.INTEGER,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

  crafting_recipes.associate = (db) => {


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












































    db.crafting_recipes.hasMany(db.recipe_ingredients, {
      as: 'recipe_ingredients_recipe',
      foreignKey: {
          name: 'recipeId',
      },
      constraints: false,
    });








//end loop



    db.crafting_recipes.belongsTo(db.items, {
      as: 'output_item',
      foreignKey: {
        name: 'output_itemId',
      },
      constraints: false,
    });

    db.crafting_recipes.belongsTo(db.locations, {
      as: 'required_station_location',
      foreignKey: {
        name: 'required_station_locationId',
      },
      constraints: false,
    });




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

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



  return crafting_recipes;
};


