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

school_name_om: {
        type: DataTypes.TEXT,
      
      

      },

school_name_am: {
        type: DataTypes.TEXT,
      
      

      },

school_name_en: {
        type: DataTypes.TEXT,
      
      

      },

welcome_message_om: {
        type: DataTypes.TEXT,
      
      

      },

welcome_message_am: {
        type: DataTypes.TEXT,
      
      

      },

welcome_message_en: {
        type: DataTypes.TEXT,
      
      

      },

address_text: {
        type: DataTypes.TEXT,
      
      

      },

map_embed_url: {
        type: DataTypes.TEXT,
      
      

      },

public_phone_numbers: {
        type: DataTypes.TEXT,
      
      

      },

public_emails: {
        type: DataTypes.TEXT,
      
      

      },

social_links: {
        type: DataTypes.TEXT,
      
      

      },

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

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

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


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

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



  return school_settings;
};


