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,
      },

channel: {
        type: DataTypes.ENUM,
      
      

        values: [

"push",


"sms",


"email",


"voice"

        ],

      },

scheduled_at: {
        type: DataTypes.DATE,
      
      

      },

state: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"sent",


"failed",


"cancelled"

        ],

      },

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

    db.reminders.belongsTo(db.calendar_events, {
      as: 'event',
      foreignKey: {
        name: 'eventId',
      },
      constraints: false,
    });

    db.reminders.belongsTo(db.users, {
      as: 'recipient_user',
      foreignKey: {
        name: 'recipient_userId',
      },
      constraints: false,
    });

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




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

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



  return reminders;
};


