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

severity: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"medium",


"high",


"critical"

        ],

      },

client_platform: {
        type: DataTypes.TEXT,
      
      

      },

client_version: {
        type: DataTypes.TEXT,
      
      

      },

reported_at: {
        type: DataTypes.DATE,
      
      

      },

stacktrace: {
        type: DataTypes.TEXT,
      
      

      },

context_payload: {
        type: DataTypes.TEXT,
      
      

      },

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

  app_crash_reports.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.app_crash_reports.belongsTo(db.marketplace_apps, {
      as: 'marketplace_app',
      foreignKey: {
        name: 'marketplace_appId',
      },
      constraints: false,
    });

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

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




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

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



  return app_crash_reports;
};


