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

frequency_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"daily",


"weekly",


"custom"

        ],

      },

time_of_day: {
        type: DataTypes.TEXT,
      
      

      },

days_of_week: {
        type: DataTypes.TEXT,
      
      

      },

effective_from: {
        type: DataTypes.DATE,
      
      

      },

effective_until: {
        type: DataTypes.DATE,
      
      

      },

requires_confirmation: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  medication_schedules.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.medication_schedules.belongsTo(db.medications, {
      as: 'medication',
      foreignKey: {
        name: 'medicationId',
      },
      constraints: false,
    });

    db.medication_schedules.belongsTo(db.patients, {
      as: 'patient',
      foreignKey: {
        name: 'patientId',
      },
      constraints: false,
    });

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




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

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



  return medication_schedules;
};


