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

camp_name: {
        type: DataTypes.TEXT,
      
      

      },

camp_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"base_camp",


"outreach_camp",


"vaccination_camp"

        ],

      },

start_at: {
        type: DataTypes.DATE,
      
      

      },

end_at: {
        type: DataTypes.DATE,
      
      

      },

location_label: {
        type: DataTypes.TEXT,
      
      

      },

address_line: {
        type: DataTypes.TEXT,
      
      

      },

latitude: {
        type: DataTypes.DECIMAL,
      
      

      },

longitude: {
        type: DataTypes.DECIMAL,
      
      

      },

camp_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"planned",


"ongoing",


"completed",


"cancelled"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  medical_camps.associate = (db) => {


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







    db.medical_camps.hasMany(db.patient_profiles, {
      as: 'patient_profiles_registered_at_camp',
      foreignKey: {
          name: 'registered_at_campId',
      },
      constraints: false,
    });



    db.medical_camps.hasMany(db.appointments, {
      as: 'appointments_camp',
      foreignKey: {
          name: 'campId',
      },
      constraints: false,
    });










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







    db.medical_camps.hasMany(db.feedbacks, {
      as: 'feedbacks_camp',
      foreignKey: {
          name: 'campId',
      },
      constraints: false,
    });



//end loop



    db.medical_camps.belongsTo(db.organizations, {
      as: 'organizer_organization',
      foreignKey: {
        name: 'organizer_organizationId',
      },
      constraints: false,
    });

    db.medical_camps.belongsTo(db.doctor_profiles, {
      as: 'camp_lead_doctor',
      foreignKey: {
        name: 'camp_lead_doctorId',
      },
      constraints: false,
    });




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

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



  return medical_camps;
};


