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

supplement_name: {
        type: DataTypes.TEXT,
      
      

      },

form: {
        type: DataTypes.ENUM,
      
      

        values: [

"capsule",


"tablet",


"powder",


"liquid",


"gummy",


"patch",


"topical",


"other"

        ],

      },

dose_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

dose_unit: {
        type: DataTypes.TEXT,
      
      

      },

timing: {
        type: DataTypes.TEXT,
      
      

      },

with_food: {
        type: DataTypes.ENUM,
      
      

        values: [

"with_food",


"empty_stomach",


"either",


"unknown"

        ],

      },

brand: {
        type: DataTypes.TEXT,
      
      

      },

cost_per_dose: {
        type: DataTypes.DECIMAL,
      
      

      },

reason: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

      },

cycle_on_days: {
        type: DataTypes.INTEGER,
      
      

      },

cycle_off_days: {
        type: DataTypes.INTEGER,
      
      

      },

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

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




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

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



  return supplements;
};


