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

profile_name: {
        type: DataTypes.TEXT,
      
      

      },

base_color: {
        type: DataTypes.ENUM,
      
      

        values: [

"red",


"orange",


"yellow",


"green",


"blue",


"purple",


"pink",


"white",


"gray",


"black",


"custom"

        ],

      },

custom_color_hex: {
        type: DataTypes.TEXT,
      
      

      },

face_style: {
        type: DataTypes.ENUM,
      
      

        values: [

"default",


"smile",


"grin",


"surprised",


"sleepy",


"silly"

        ],

      },

pattern_style: {
        type: DataTypes.ENUM,
      
      

        values: [

"none",


"stripes",


"polka_dots",


"stars",


"waves",


"checker"

        ],

      },

pattern_color: {
        type: DataTypes.ENUM,
      
      

        values: [

"white",


"black",


"red",


"blue",


"green",


"yellow",


"custom"

        ],

      },

pattern_custom_hex: {
        type: DataTypes.TEXT,
      
      

      },

hat_style: {
        type: DataTypes.ENUM,
      
      

        values: [

"none",


"cap",


"beanie",


"crown",


"graduation_cap",


"headphones"

        ],

      },

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

      },

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

  avatar_customizations.associate = (db) => {


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
























    db.avatar_customizations.hasMany(db.match_players, {
      as: 'match_players_avatar_customization',
      foreignKey: {
          name: 'avatar_customizationId',
      },
      constraints: false,
    });














//end loop



    db.avatar_customizations.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });



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


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

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



  return avatar_customizations;
};


