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

due_at: {
        type: DataTypes.DATE,
      
      

      },

administered_at: {
        type: DataTypes.DATE,
      
      

      },

vaccination_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"scheduled",


"completed",


"missed",


"cancelled"

        ],

      },

administered_by: {
        type: DataTypes.TEXT,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  patient_vaccinations.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity



















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








//end loop



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

    db.patient_vaccinations.belongsTo(db.vaccinations, {
      as: 'vaccination',
      foreignKey: {
        name: 'vaccinationId',
      },
      constraints: false,
    });

    db.patient_vaccinations.belongsTo(db.medical_camps, {
      as: 'administered_at_camp',
      foreignKey: {
        name: 'administered_at_campId',
      },
      constraints: false,
    });

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




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

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



  return patient_vaccinations;
};


