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

category: {
        type: DataTypes.ENUM,
      
      

        values: [

"preference",


"location",


"airline",


"contact",


"timezone",


"payment",


"note"

        ],

      },

key: {
        type: DataTypes.TEXT,
      
      

      },

value: {
        type: DataTypes.TEXT,
      
      

      },

visibility: {
        type: DataTypes.ENUM,
      
      

        values: [

"private",


"workspace"

        ],

      },

confidence: {
        type: DataTypes.DECIMAL,
      
      

      },

last_used_at: {
        type: DataTypes.DATE,
      
      

      },

use_count: {
        type: DataTypes.INTEGER,
      
      

      },

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

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

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




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

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



  return memory_items;
};


