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

store_description_ar: {
        type: DataTypes.TEXT,
      
      

      },

store_description_en: {
        type: DataTypes.TEXT,
      
      

      },

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

  footer_content_blocks.associate = (db) => {

    db.footer_content_blocks.belongsToMany(db.social_links, {
      as: 'social_links',
      foreignKey: {
        name: 'footer_content_blocks_social_linksId',
      },
      constraints: false,
      through: 'footer_content_blocksSocial_linksSocial_links',
    });

    db.footer_content_blocks.belongsToMany(db.social_links, {
      as: 'social_links_filter',
      foreignKey: {
        name: 'footer_content_blocks_social_linksId',
      },
      constraints: false,
      through: 'footer_content_blocksSocial_linksSocial_links',
    });

    db.footer_content_blocks.belongsToMany(db.footer_links, {
      as: 'footer_links',
      foreignKey: {
        name: 'footer_content_blocks_footer_linksId',
      },
      constraints: false,
      through: 'footer_content_blocksFooter_linksFooter_links',
    });

    db.footer_content_blocks.belongsToMany(db.footer_links, {
      as: 'footer_links_filter',
      foreignKey: {
        name: 'footer_content_blocks_footer_linksId',
      },
      constraints: false,
      through: 'footer_content_blocksFooter_linksFooter_links',
    });

    db.footer_content_blocks.belongsToMany(db.payment_badges, {
      as: 'payment_badges',
      foreignKey: {
        name: 'footer_content_blocks_payment_badgesId',
      },
      constraints: false,
      through: 'footer_content_blocksPayment_badgesPayment_badges',
    });

    db.footer_content_blocks.belongsToMany(db.payment_badges, {
      as: 'payment_badges_filter',
      foreignKey: {
        name: 'footer_content_blocks_payment_badgesId',
      },
      constraints: false,
      through: 'footer_content_blocksPayment_badgesPayment_badges',
    });


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



































    db.footer_content_blocks.hasMany(db.social_links, {
      as: 'social_links_footer_content_block',
      foreignKey: {
          name: 'footer_content_blockId',
      },
      constraints: false,
    });


    db.footer_content_blocks.hasMany(db.footer_links, {
      as: 'footer_links_footer_content_block',
      foreignKey: {
          name: 'footer_content_blockId',
      },
      constraints: false,
    });


    db.footer_content_blocks.hasMany(db.payment_badges, {
      as: 'payment_badges_footer_content_block',
      foreignKey: {
          name: 'footer_content_blockId',
      },
      constraints: false,
    });








//end loop






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

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



  return footer_content_blocks;
};


