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

source: {
        type: DataTypes.ENUM,
      
      

        values: [

"library",


"upload",


"scan_claim"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"saved",


"in_progress",


"completed",


"archived"

        ],

      },

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

      },

downloaded_at: {
        type: DataTypes.DATE,
      
      

      },

progress_percent: {
        type: DataTypes.DECIMAL,
      
      

      },

current_location: {
        type: DataTypes.INTEGER,
      
      

      },

last_opened_at: {
        type: DataTypes.DATE,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

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

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

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




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

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



  return user_library_items;
};


