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

goal_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"lose_body_fat",


"build_muscle_mass",


"improve_cardiovascular_fitness",


"increase_flexibility_mobility",


"improve_sleep_quality",


"reduce_stress_anxiety",


"manage_chronic_condition_better",


"improve_mental_health",


"optimise_nutrition",


"improve_gut_health",


"improve_hormonal_balance",


"increase_energy_levels",


"longevity_anti_ageing",


"athletic_performance",


"post_surgery_recovery",


"pregnancy_preparation",


"postpartum_recovery",


"improve_sexual_health",


"improve_fertility",


"quit_smoking_or_alcohol",


"build_better_daily_habits",


"improve_cognitive_performance",


"support_family_member_health"

        ],

      },

follow_up_answer: {
        type: DataTypes.TEXT,
      
      

      },

target_date: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

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




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

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



  return goals;
};


