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

medicine_label: {
        type: DataTypes.TEXT,
      
      

      },

dosage: {
        type: DataTypes.TEXT,
      
      

      },

frequency: {
        type: DataTypes.ENUM,
      
      

        values: [

"once_daily",


"twice_daily",


"thrice_daily",


"every_6_hours",


"every_8_hours",


"weekly",


"as_needed"

        ],

      },

start_at: {
        type: DataTypes.DATE,
      
      

      },

end_at: {
        type: DataTypes.DATE,
      
      

      },

next_due_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"paused",


"completed",


"cancelled"

        ],

      },

instructions: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.medicine_reminders.belongsTo(db.medical_reports, {
      as: 'medical_report',
      foreignKey: {
        name: 'medical_reportId',
      },
      constraints: false,
    });




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

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



  return medicine_reminders;
};


