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_ar: {
        type: DataTypes.TEXT,
      
      

      },

site_tagline_ar: {
        type: DataTypes.TEXT,
      
      

      },

primary_font: {
        type: DataTypes.TEXT,
      
      

      },

direction: {
        type: DataTypes.ENUM,
      
      

        values: [

"rtl",


"ltr"

        ],

      },

primary_color_hex: {
        type: DataTypes.TEXT,
      
      

      },

accent_color_hex: {
        type: DataTypes.TEXT,
      
      

      },

seo_default_title_ar: {
        type: DataTypes.TEXT,
      
      

      },

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

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

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


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

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



  return site_settings;
};


