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

subject_label: {
        type: DataTypes.TEXT,
      
      

      },

level_label: {
        type: DataTypes.TEXT,
      
      

      },

issued_at: {
        type: DataTypes.DATE,
      
      

      },

certificate_html: {
        type: DataTypes.TEXT,
      
      

      },

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

  certificates.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.certificates.belongsTo(db.bookings, {
      as: 'booking',
      foreignKey: {
        name: 'bookingId',
      },
      constraints: false,
    });

    db.certificates.belongsTo(db.users, {
      as: 'learner',
      foreignKey: {
        name: 'learnerId',
      },
      constraints: false,
    });

    db.certificates.belongsTo(db.users, {
      as: 'tutor',
      foreignKey: {
        name: 'tutorId',
      },
      constraints: false,
    });




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

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



  return certificates;
};


