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

code_name: {
        type: DataTypes.TEXT,
      
      

      },

target_path: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

scan_count: {
        type: DataTypes.INTEGER,
      
      

      },

last_scanned_at: {
        type: DataTypes.DATE,
      
      

      },

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

  qr_links.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.qr_links.hasMany(db.file, {
      as: 'qr_image',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.qr_links.getTableName(),
        belongsToColumn: 'qr_image',
      },
    });


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

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



  return qr_links;
};


