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

reminder_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"medicine",


"vaccination",


"appointment",


"follow_up"

        ],

      },

scheduled_at: {
        type: DataTypes.DATE,
      
      

      },

sent_at: {
        type: DataTypes.DATE,
      
      

      },

channel: {
        type: DataTypes.ENUM,
      
      

        values: [

"push",


"email",


"sms"

        ],

      },

delivery_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"sent",


"delivered",


"failed"

        ],

      },

message_text: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.reminders.belongsTo(db.prescription_items, {
      as: 'prescription_item',
      foreignKey: {
        name: 'prescription_itemId',
      },
      constraints: false,
    });

    db.reminders.belongsTo(db.patient_vaccinations, {
      as: 'patient_vaccination',
      foreignKey: {
        name: 'patient_vaccinationId',
      },
      constraints: false,
    });

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




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

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



  return reminders;
};


