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,
      
      

      },

message: {
        type: DataTypes.TEXT,
      
      

      },

audience: {
        type: DataTypes.ENUM,
      
      

        values: [

"all",


"guardians",


"staff",


"k_2",


"grades_3_5",


"grades_6_12"

        ],

      },

publish_datetime: {
        type: DataTypes.DATE,
      
      

      },

expire_datetime: {
        type: DataTypes.DATE,
      
      

      },

is_published: {
        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.belongsTo(db.camp_sessions, {
      as: 'camp_session',
      foreignKey: {
        name: 'camp_sessionId',
      },
      constraints: false,
    });




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

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



  return announcements;
};


