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

section_title: {
        type: DataTypes.TEXT,
      
      

      },

section_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"hero",


"featured_products",


"category_grid",


"banner",


"html_block"

        ],

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

html_content: {
        type: DataTypes.TEXT,
      
      

      },

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

  home_sections.associate = (db) => {


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

























    db.home_sections.hasMany(db.home_section_items, {
      as: 'home_section_items_home_section',
      foreignKey: {
          name: 'home_sectionId',
      },
      constraints: false,
    });






//end loop





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


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

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



  return home_sections;
};


