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

title: {
        type: DataTypes.TEXT,
      
      

      },

summary: {
        type: DataTypes.TEXT,
      
      

      },

icon_name: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

  feature_highlights.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.feature_highlights.belongsTo(db.pages, {
      as: 'page',
      foreignKey: {
        name: 'pageId',
      },
      constraints: false,
    });



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


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

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



  return feature_highlights;
};


