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

event_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"request_created",


"coordinator_assigned",


"status_changed",


"message_sent",


"document_uploaded",


"payment_completed",


"case_closed",


"note_added"

        ],

      },

event_title: {
        type: DataTypes.TEXT,
      
      

      },

event_detail: {
        type: DataTypes.TEXT,
      
      

      },

event_at: {
        type: DataTypes.DATE,
      
      

      },

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

  request_timeline_events.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.request_timeline_events.belongsTo(db.service_requests, {
      as: 'service_request',
      foreignKey: {
        name: 'service_requestId',
      },
      constraints: false,
    });

    db.request_timeline_events.belongsTo(db.users, {
      as: 'actor_user',
      foreignKey: {
        name: 'actor_userId',
      },
      constraints: false,
    });

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




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

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



  return request_timeline_events;
};


