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

name: {
        type: DataTypes.TEXT,
      
      

      },

slot: {
        type: DataTypes.ENUM,
      
      

        values: [

"hair",


"eyes",


"skin",


"body",


"top",


"bottom",


"shoes",


"accessory",


"backpack"

        ],

      },

rarity: {
        type: DataTypes.ENUM,
      
      

        values: [

"common",


"uncommon",


"rare",


"epic",


"legendary"

        ],

      },

price: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

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

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

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


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

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



  return customization_items;
};


