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

item_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"product",


"category",


"external_link",


"image_only"

        ],

      },

link_url: {
        type: DataTypes.TEXT,
      
      

      },

item_title: {
        type: DataTypes.TEXT,
      
      

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

  home_section_items.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.home_section_items.belongsTo(db.home_sections, {
      as: 'home_section',
      foreignKey: {
        name: 'home_sectionId',
      },
      constraints: false,
    });

    db.home_section_items.belongsTo(db.products, {
      as: 'product',
      foreignKey: {
        name: 'productId',
      },
      constraints: false,
    });

    db.home_section_items.belongsTo(db.categories, {
      as: 'category',
      foreignKey: {
        name: 'categoryId',
      },
      constraints: false,
    });



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


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

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



  return home_section_items;
};


