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

      },

content: {
        type: DataTypes.TEXT,
      
      

      },

publish_at: {
        type: DataTypes.DATE,
      
      

      },

expire_at: {
        type: DataTypes.DATE,
      
      

      },

visibility: {
        type: DataTypes.ENUM,
      
      

        values: [

"all",


"managers",


"hr_only"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"published",


"archived"

        ],

      },

      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.belongsTo(db.companies, {
      as: 'company',
      foreignKey: {
        name: 'companyId',
      },
      constraints: false,
    });

    db.announcements.belongsTo(db.users, {
      as: 'author',
      foreignKey: {
        name: 'authorId',
      },
      constraints: false,
    });

    db.announcements.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return announcements;
};


