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

scheduled_start_at: {
        type: DataTypes.DATE,
      
      

      },

scheduled_end_at: {
        type: DataTypes.DATE,
      
      

      },

appointment_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"in_person",


"telemedicine",


"camp_visit"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"requested",


"confirmed",


"in_progress",


"completed",


"cancelled",


"no_show"

        ],

      },

reason_for_visit: {
        type: DataTypes.TEXT,
      
      

      },

meeting_link: {
        type: DataTypes.TEXT,
      
      

      },

meeting_room: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.appointments.belongsTo(db.city_doctors, {
      as: 'city_doctor',
      foreignKey: {
        name: 'city_doctorId',
      },
      constraints: false,
    });

    db.appointments.belongsTo(db.rural_doctors, {
      as: 'rural_doctor',
      foreignKey: {
        name: 'rural_doctorId',
      },
      constraints: false,
    });

    db.appointments.belongsTo(db.medical_camps, {
      as: 'medical_camp',
      foreignKey: {
        name: 'medical_campId',
      },
      constraints: false,
    });




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

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



  return appointments;
};


