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

title_om: {
        type: DataTypes.TEXT,
      
      

      },

title_am: {
        type: DataTypes.TEXT,
      
      

      },

title_en: {
        type: DataTypes.TEXT,
      
      

      },

excerpt_om: {
        type: DataTypes.TEXT,
      
      

      },

excerpt_am: {
        type: DataTypes.TEXT,
      
      

      },

excerpt_en: {
        type: DataTypes.TEXT,
      
      

      },

content_om: {
        type: DataTypes.TEXT,
      
      

      },

content_am: {
        type: DataTypes.TEXT,
      
      

      },

content_en: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"published",


"archived"

        ],

      },

published_at: {
        type: DataTypes.DATE,
      
      

      },

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

  news_posts.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.news_posts.belongsTo(db.staff_members, {
      as: 'author',
      foreignKey: {
        name: 'authorId',
      },
      constraints: false,
    });



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


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

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



  return news_posts;
};


