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

source_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"transaction",


"anomaly",


"alert",


"metrics_snapshot",


"forecast",


"budget",


"file"

        ],

      },

source_label: {
        type: DataTypes.TEXT,
      
      

      },

source_reference: {
        type: DataTypes.TEXT,
      
      

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

occurred_at: {
        type: DataTypes.DATE,
      
      

      },

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

  message_citations.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.message_citations.belongsTo(db.chat_messages, {
      as: 'message',
      foreignKey: {
        name: 'messageId',
      },
      constraints: false,
    });

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




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

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



  return message_citations;
};


