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

name: {
        type: DataTypes.TEXT,
      
      

      },

rarity: {
        type: DataTypes.ENUM,
      
      

        values: [

"common",


"uncommon",


"rare",


"epic",


"legendary"

        ],

      },

active_time: {
        type: DataTypes.ENUM,
      
      

        values: [

"day",


"night",


"any"

        ],

      },

preferred_weather: {
        type: DataTypes.ENUM,
      
      

        values: [

"sunny",


"rain",


"storm",


"cloudy",


"fog",


"heat_wave",


"wind",


"any"

        ],

      },

base_bite_rate: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  fish_species.associate = (db) => {


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










































    db.fish_species.hasMany(db.fishing_catches, {
      as: 'fishing_catches_fish_species',
      foreignKey: {
          name: 'fish_speciesId',
      },
      constraints: false,
    });










//end loop



    db.fish_species.belongsTo(db.items, {
      as: 'item',
      foreignKey: {
        name: 'itemId',
      },
      constraints: false,
    });



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


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

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



  return fish_species;
};


