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

headline: {
        type: DataTypes.TEXT,
      
      

      },

content: {
        type: DataTypes.TEXT,
      
      

      },

audience: {
        type: DataTypes.ENUM,
      
      

        values: [

"all_users",


"admins",


"buyers",


"finance",


"warehouse"

        ],

      },

publish_from: {
        type: DataTypes.DATE,
      
      

      },

publish_to: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

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

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




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

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



  return ui_announcements;
};


