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

style_name: {
        type: DataTypes.TEXT,
      
      

      },

username_color_hex: {
        type: DataTypes.TEXT,
      
      

      },

bio_font_family: {
        type: DataTypes.TEXT,
      
      

      },

panel_order_json: {
        type: DataTypes.TEXT,
      
      

      },

profile_layout: {
        type: DataTypes.ENUM,
      
      

        values: [

"classic",


"modern",


"minimal",


"streamer",


"storefront"

        ],

      },

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

      },

pronouns_text: {
        type: DataTypes.TEXT,
      
      

      },

custom_css: {
        type: DataTypes.TEXT,
      
      

      },

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

  profile_styles.associate = (db) => {


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






    db.profile_styles.hasMany(db.creator_profiles, {
      as: 'creator_profiles_profile_style',
      foreignKey: {
          name: 'profile_styleId',
      },
      constraints: false,
    });































//end loop



    db.profile_styles.belongsTo(db.users, {
      as: 'owner_user',
      foreignKey: {
        name: 'owner_userId',
      },
      constraints: false,
    });

    db.profile_styles.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });



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

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


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

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



  return profile_styles;
};


