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

store_name: {
        type: DataTypes.TEXT,
      
      

      },

store_tagline: {
        type: DataTypes.TEXT,
      
      

      },

default_currency: {
        type: DataTypes.TEXT,
      
      

      },

support_phone: {
        type: DataTypes.TEXT,
      
      

      },

support_email: {
        type: DataTypes.TEXT,
      
      

      },

whatsapp_number: {
        type: DataTypes.TEXT,
      
      

      },

address_text: {
        type: DataTypes.TEXT,
      
      

      },

primary_language: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

maintenance_message: {
        type: DataTypes.TEXT,
      
      

      },

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

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

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


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

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



  return store_settings;
};


