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

appointment_start: {
        type: DataTypes.DATE,
      
      

      },

appointment_end: {
        type: DataTypes.DATE,
      
      

      },

appointment_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"gp",


"specialist",


"check_up",


"test",


"procedure",


"therapy",


"dentist",


"optometrist",


"other"

        ],

      },

clinic_location: {
        type: DataTypes.TEXT,
      
      

      },

notes_to_discuss: {
        type: DataTypes.TEXT,
      
      

      },

documents_to_bring: {
        type: DataTypes.TEXT,
      
      

      },

post_appointment_notes: {
        type: DataTypes.TEXT,
      
      

      },

follow_up_instructions: {
        type: DataTypes.TEXT,
      
      

      },

follow_up_reminder_at: {
        type: DataTypes.DATE,
      
      

      },

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

  medical_appointments.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.medical_appointments.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.medical_appointments.belongsTo(db.healthcare_providers, {
      as: 'provider',
      foreignKey: {
        name: 'providerId',
      },
      constraints: false,
    });




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

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



  return medical_appointments;
};


