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

store_description: {
        type: DataTypes.TEXT,
      
      

      },

copyright_text: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

footer_banner_text: {
        type: DataTypes.TEXT,
      
      

      },

footer_banner_url: {
        type: DataTypes.TEXT,
      
      

      },

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

  footer_settings.associate = (db) => {

    db.footer_settings.belongsToMany(db.social_links, {
      as: 'social_links',
      foreignKey: {
        name: 'footer_settings_social_linksId',
      },
      constraints: false,
      through: 'footer_settingsSocial_linksSocial_links',
    });

    db.footer_settings.belongsToMany(db.social_links, {
      as: 'social_links_filter',
      foreignKey: {
        name: 'footer_settings_social_linksId',
      },
      constraints: false,
      through: 'footer_settingsSocial_linksSocial_links',
    });

    db.footer_settings.belongsToMany(db.footer_links, {
      as: 'footer_links',
      foreignKey: {
        name: 'footer_settings_footer_linksId',
      },
      constraints: false,
      through: 'footer_settingsFooter_linksFooter_links',
    });

    db.footer_settings.belongsToMany(db.footer_links, {
      as: 'footer_links_filter',
      foreignKey: {
        name: 'footer_settings_footer_linksId',
      },
      constraints: false,
      through: 'footer_settingsFooter_linksFooter_links',
    });

    db.footer_settings.belongsToMany(db.payment_icons, {
      as: 'payment_icons',
      foreignKey: {
        name: 'footer_settings_payment_iconsId',
      },
      constraints: false,
      through: 'footer_settingsPayment_iconsPayment_icons',
    });

    db.footer_settings.belongsToMany(db.payment_icons, {
      as: 'payment_icons_filter',
      foreignKey: {
        name: 'footer_settings_payment_iconsId',
      },
      constraints: false,
      through: 'footer_settingsPayment_iconsPayment_icons',
    });


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



































    db.footer_settings.hasMany(db.social_links, {
      as: 'social_links_footer',
      foreignKey: {
          name: 'footerId',
      },
      constraints: false,
    });


    db.footer_settings.hasMany(db.footer_links, {
      as: 'footer_links_footer',
      foreignKey: {
          name: 'footerId',
      },
      constraints: false,
    });



    db.footer_settings.hasMany(db.payment_icons, {
      as: 'payment_icons_footer',
      foreignKey: {
          name: 'footerId',
      },
      constraints: false,
    });





//end loop





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

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


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

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



  return footer_settings;
};


