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

protocol: {
        type: DataTypes.ENUM,
      
      

        values: [

"12_12",


"14_10",


"16_8",


"18_6",


"20_4",


"omad",


"5_2",


"alternate_day",


"custom"

        ],

      },

fast_start: {
        type: DataTypes.DATE,
      
      

      },

fast_end: {
        type: DataTypes.DATE,
      
      

      },

eating_window_start: {
        type: DataTypes.DATE,
      
      

      },

eating_window_end: {
        type: DataTypes.DATE,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

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




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

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



  return fasting_sessions;
};


