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

program_name: {
        type: DataTypes.TEXT,
      
      

      },

program_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"preboarding",


"onboarding",


"continuous"

        ],

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

published_at: {
        type: DataTypes.DATE,
      
      

      },

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

  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.programs.hasMany(db.learning_paths, {
      as: 'learning_paths_program',
      foreignKey: {
          name: 'programId',
      },
      constraints: false,
    });



    db.programs.hasMany(db.checklists, {
      as: 'checklists_program',
      foreignKey: {
          name: 'programId',
      },
      constraints: false,
    });



    db.programs.hasMany(db.enrollments, {
      as: 'enrollments_program',
      foreignKey: {
          name: 'programId',
      },
      constraints: false,
    });

































//end loop



    db.programs.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });




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

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



  return programs;
};


