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

list_name: {
        type: DataTypes.TEXT,
      
      

      },

list_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"reorder",


"favorites",


"par",


"seasonal"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  saved_lists.associate = (db) => {


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























    db.saved_lists.hasMany(db.saved_list_items, {
      as: 'saved_list_items_saved_list',
      foreignKey: {
          name: 'saved_listId',
      },
      constraints: false,
    });



//end loop



    db.saved_lists.belongsTo(db.accounts, {
      as: 'account',
      foreignKey: {
        name: 'accountId',
      },
      constraints: false,
    });

    db.saved_lists.belongsTo(db.users, {
      as: 'owner',
      foreignKey: {
        name: 'ownerId',
      },
      constraints: false,
    });




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

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



  return saved_lists;
};


