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

scan_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"cover",


"page",


"shelf"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"started",


"verifying",


"failed",


"completed",


"flagged"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

ended_at: {
        type: DataTypes.DATE,
      
      

      },

frames_analyzed: {
        type: DataTypes.INTEGER,
      
      

      },

pages_detected: {
        type: DataTypes.INTEGER,
      
      

      },

confidence_score: {
        type: DataTypes.DECIMAL,
      
      

      },

page_turning_detected: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

duplicate_page_detected: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

fraud_reason: {
        type: DataTypes.TEXT,
      
      

      },

coins_awarded: {
        type: DataTypes.INTEGER,
      
      

      },

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

  camera_scan_sessions.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity













    db.camera_scan_sessions.hasMany(db.coin_ledger_entries, {
      as: 'coin_ledger_entries_scan_session',
      foreignKey: {
          name: 'scan_sessionId',
      },
      constraints: false,
    });























    db.camera_scan_sessions.hasMany(db.fraud_flags, {
      as: 'fraud_flags_scan_session',
      foreignKey: {
          name: 'scan_sessionId',
      },
      constraints: false,
    });





//end loop



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

    db.camera_scan_sessions.belongsTo(db.books, {
      as: 'book',
      foreignKey: {
        name: 'bookId',
      },
      constraints: false,
    });




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

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



  return camera_scan_sessions;
};


