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

instance_name: {
        type: DataTypes.TEXT,
      
      

      },

config_json: {
        type: DataTypes.TEXT,
      
      

      },

x: {
        type: DataTypes.INTEGER,
      
      

      },

y: {
        type: DataTypes.INTEGER,
      
      

      },

width: {
        type: DataTypes.INTEGER,
      
      

      },

height: {
        type: DataTypes.INTEGER,
      
      

      },

z_index: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  overlay_widgets.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.overlay_widgets.belongsTo(db.overlay_profiles, {
      as: 'overlay_profile',
      foreignKey: {
        name: 'overlay_profileId',
      },
      constraints: false,
    });

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

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




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

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



  return overlay_widgets;
};


