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

name: {
        type: DataTypes.TEXT,
      
      

      },

tagline: {
        type: DataTypes.TEXT,
      
      

      },

unlock_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"achievement",


"event",


"shop",


"starter",


"admin_grant"

        ],

      },

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

      },

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

  titles.associate = (db) => {


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











    db.titles.hasMany(db.inventory_items, {
      as: 'inventory_items_title_item',
      foreignKey: {
          name: 'title_itemId',
      },
      constraints: false,
    });




    db.titles.hasMany(db.achievements, {
      as: 'achievements_reward_title',
      foreignKey: {
          name: 'reward_titleId',
      },
      constraints: false,
    });


















    db.titles.hasMany(db.daily_rewards, {
      as: 'daily_rewards_title_item',
      foreignKey: {
          name: 'title_itemId',
      },
      constraints: false,
    });







//end loop






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

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



  return titles;
};


