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

name: {
        type: DataTypes.TEXT,
      
      

      },

icon_name: {
        type: DataTypes.TEXT,
      
      

      },

author_name: {
        type: DataTypes.TEXT,
      
      

      },

widget_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"chat_box",


"goal_meter",


"sub_bar",


"now_playing",


"poll",


"alert_box",


"custom"

        ],

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

      },

schema_json: {
        type: DataTypes.TEXT,
      
      

      },

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

  widget_catalog_items.associate = (db) => {


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























    db.widget_catalog_items.hasMany(db.overlay_widgets, {
      as: 'overlay_widgets_catalog_item',
      foreignKey: {
          name: 'catalog_itemId',
      },
      constraints: false,
    });














//end loop



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



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


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

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



  return widget_catalog_items;
};


