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

page_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"about_history",


"about_mission_vision_values",


"about_principal_message",


"about_facilities",


"about_achievements",


"parents_information",


"student_guide",


"admissions",


"contact",


"alumni"

        ],

      },

title_om: {
        type: DataTypes.TEXT,
      
      

      },

title_am: {
        type: DataTypes.TEXT,
      
      

      },

title_en: {
        type: DataTypes.TEXT,
      
      

      },

content_om: {
        type: DataTypes.TEXT,
      
      

      },

content_am: {
        type: DataTypes.TEXT,
      
      

      },

content_en: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

published_at: {
        type: DataTypes.DATE,
      
      

      },

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

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


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

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



  return pages;
};


