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

snapshot_at: {
        type: DataTypes.DATE,
      
      

      },

study_hours_last_7d: {
        type: DataTypes.DECIMAL,
      
      

      },

study_hours_last_30d: {
        type: DataTypes.DECIMAL,
      
      

      },

retention_estimate: {
        type: DataTypes.DECIMAL,
      
      

      },

test_performance_avg: {
        type: DataTypes.DECIMAL,
      
      

      },

cards_due_count: {
        type: DataTypes.INTEGER,
      
      

      },

streak_days: {
        type: DataTypes.INTEGER,
      
      

      },

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

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

    db.dashboard_snapshots.belongsTo(db.workspaces, {
      as: 'workspace',
      foreignKey: {
        name: 'workspaceId',
      },
      constraints: false,
    });

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




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

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



  return dashboard_snapshots;
};


