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

rating: {
        type: DataTypes.INTEGER,
      
      

      },

comments: {
        type: DataTypes.TEXT,
      
      

      },

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

visibility: {
        type: DataTypes.ENUM,
      
      

        values: [

"private",


"internal",


"public"

        ],

      },

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

  feedbacks.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.feedbacks.belongsTo(db.patient_profiles, {
      as: 'patient',
      foreignKey: {
        name: 'patientId',
      },
      constraints: false,
    });

    db.feedbacks.belongsTo(db.doctor_profiles, {
      as: 'doctor',
      foreignKey: {
        name: 'doctorId',
      },
      constraints: false,
    });

    db.feedbacks.belongsTo(db.consultations, {
      as: 'consultation',
      foreignKey: {
        name: 'consultationId',
      },
      constraints: false,
    });

    db.feedbacks.belongsTo(db.medical_camps, {
      as: 'camp',
      foreignKey: {
        name: 'campId',
      },
      constraints: false,
    });

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




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

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



  return feedbacks;
};


