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

store_name: {
        type: DataTypes.TEXT,
      
      

      },

default_language: {
        type: DataTypes.TEXT,
      
      

      },

default_currency: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

adsense_head_code: {
        type: DataTypes.TEXT,
      
      

      },

footer_bottom_text: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

footer_partner_banner_text: {
        type: DataTypes.TEXT,
      
      

      },

footer_partner_banner_url: {
        type: DataTypes.TEXT,
      
      

      },

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

  site_settings.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.site_settings.hasMany(db.file, {
      as: 'store_logo',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.site_settings.getTableName(),
        belongsToColumn: 'store_logo',
      },
    });

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


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

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



  return site_settings;
};


