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

name: {
        type: DataTypes.TEXT,
      
      

      },

cosmetic_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"color",


"face",


"pattern",


"hat",


"title",


"badge"

        ],

      },

rarity: {
        type: DataTypes.ENUM,
      
      

        values: [

"common",


"uncommon",


"rare",


"epic",


"legendary",


"mythic"

        ],

      },

asset_key: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  cosmetics.associate = (db) => {


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









    db.cosmetics.hasMany(db.box_items, {
      as: 'box_items_cosmetic',
      foreignKey: {
          name: 'cosmeticId',
      },
      constraints: false,
    });


    db.cosmetics.hasMany(db.purchases, {
      as: 'purchases_cosmetic',
      foreignKey: {
          name: 'cosmeticId',
      },
      constraints: false,
    });


    db.cosmetics.hasMany(db.inventory_items, {
      as: 'inventory_items_cosmetic',
      foreignKey: {
          name: 'cosmeticId',
      },
      constraints: false,
    });





















    db.cosmetics.hasMany(db.daily_rewards, {
      as: 'daily_rewards_cosmetic',
      foreignKey: {
          name: 'cosmeticId',
      },
      constraints: false,
    });







//end loop





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


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

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



  return cosmetics;
};


