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

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,
      
      

      },

visibility: {
        type: DataTypes.ENUM,
      
      

        values: [

"public",


"staff_only",


"students_only"

        ],

      },

publish_from: {
        type: DataTypes.DATE,
      
      

      },

publish_until: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

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

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


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

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



  return announcements;
};


