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

program_name: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

target_stage: {
        type: DataTypes.ENUM,
      
      

        values: [

"mild",


"moderate",


"severe",


"all"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"published",


"archived"

        ],

      },

estimated_minutes: {
        type: DataTypes.INTEGER,
      
      

      },

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

  cognitive_programs.associate = (db) => {


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













    db.cognitive_programs.hasMany(db.cognitive_exercises, {
      as: 'cognitive_exercises_program',
      foreignKey: {
          name: 'programId',
      },
      constraints: false,
    });


    db.cognitive_programs.hasMany(db.cognitive_sessions, {
      as: 'cognitive_sessions_program',
      foreignKey: {
          name: 'programId',
      },
      constraints: false,
    });
















//end loop



    db.cognitive_programs.belongsTo(db.users, {
      as: 'created_by_user',
      foreignKey: {
        name: 'created_by_userId',
      },
      constraints: false,
    });

    db.cognitive_programs.belongsTo(db.accounts, {
      as: 'accounts',
      foreignKey: {
        name: 'accountsId',
      },
      constraints: false,
    });




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

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



  return cognitive_programs;
};


