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,
      },

site_name: {
        type: DataTypes.TEXT,
      
      

      },

tagline: {
        type: DataTypes.TEXT,
      
      

      },

primary_phone: {
        type: DataTypes.TEXT,
      
      

      },

secondary_phone: {
        type: DataTypes.TEXT,
      
      

      },

whatsapp_number: {
        type: DataTypes.TEXT,
      
      

      },

contact_email: {
        type: DataTypes.TEXT,
      
      

      },

address: {
        type: DataTypes.TEXT,
      
      

      },

google_maps_embed: {
        type: DataTypes.TEXT,
      
      

      },

working_hours: {
        type: DataTypes.TEXT,
      
      

      },

facebook_url: {
        type: DataTypes.TEXT,
      
      

      },

instagram_url: {
        type: DataTypes.TEXT,
      
      

      },

linkedin_url: {
        type: DataTypes.TEXT,
      
      

      },

youtube_url: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

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


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

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



  return site_settings;
};


