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

provider: {
        type: DataTypes.ENUM,
      
      

        values: [

"osu_v2",


"musicbrainz",


"lastfm"

        ],

      },

request_method: {
        type: DataTypes.TEXT,
      
      

      },

request_path: {
        type: DataTypes.TEXT,
      
      

      },

request_query: {
        type: DataTypes.TEXT,
      
      

      },

response_status: {
        type: DataTypes.INTEGER,
      
      

      },

duration_ms: {
        type: DataTypes.INTEGER,
      
      

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

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

  api_request_logs.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.api_request_logs.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });




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

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



  return api_request_logs;
};


