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

path_name: {
        type: DataTypes.TEXT,
      
      

      },

audience: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"published",


"archived"

        ],

      },

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

  learning_paths.associate = (db) => {


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












    db.learning_paths.hasMany(db.missions, {
      as: 'missions_learning_path',
      foreignKey: {
          name: 'learning_pathId',
      },
      constraints: false,
    });




































//end loop



    db.learning_paths.belongsTo(db.programs, {
      as: 'program',
      foreignKey: {
        name: 'programId',
      },
      constraints: false,
    });

    db.learning_paths.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return learning_paths;
};


