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,
      
      

      },

start_at: {
        type: DataTypes.DATE,
      
      

      },

end_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"planned",


"scheduled",


"active",


"completed",


"cancelled"

        ],

      },

location_name: {
        type: DataTypes.TEXT,
      
      

      },

address: {
        type: DataTypes.TEXT,
      
      

      },

latitude: {
        type: DataTypes.DECIMAL,
      
      

      },

longitude: {
        type: DataTypes.DECIMAL,
      
      

      },

expected_attendees: {
        type: DataTypes.INTEGER,
      
      

      },

actual_attendees: {
        type: DataTypes.INTEGER,
      
      

      },

services_offered: {
        type: DataTypes.TEXT,
      
      

      },

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.appointments, {
      as: 'appointments_medical_camp',
      foreignKey: {
          name: 'medical_campId',
      },
      constraints: false,
    });













//end loop



    db.medical_camps.belongsTo(db.admins, {
      as: 'created_by_admin',
      foreignKey: {
        name: 'created_by_adminId',
      },
      constraints: false,
    });

    db.medical_camps.belongsTo(db.city_doctors, {
      as: 'lead_city_doctor',
      foreignKey: {
        name: 'lead_city_doctorId',
      },
      constraints: false,
    });

    db.medical_camps.belongsTo(db.rural_doctors, {
      as: 'lead_rural_doctor',
      foreignKey: {
        name: 'lead_rural_doctorId',
      },
      constraints: false,
    });




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

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



  return medical_camps;
};


