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

event_name: {
        type: DataTypes.ENUM,
      
      

        values: [

"login",


"request_created",


"request_status_changed",


"message_sent",


"document_uploaded",


"payment_succeeded",


"invoice_paid",


"webhook_delivered",


"csv_import_completed",


"csv_export_completed"

        ],

      },

metadata_json: {
        type: DataTypes.TEXT,
      
      

      },

occurred_at: {
        type: DataTypes.DATE,
      
      

      },

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

  usage_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.usage_events.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.usage_events.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });




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

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



  return usage_events;
};


