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

case_number: {
        type: DataTypes.TEXT,
      
      

      },

diagnosis: {
        type: DataTypes.TEXT,
      
      

      },

delivery_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"natural",


"csection",


"assisted"

        ],

      },

admission_date: {
        type: DataTypes.DATE,
      
      

      },

discharge_date: {
        type: DataTypes.DATE,
      
      

      },

price: {
        type: DataTypes.DECIMAL,
      
      

      },

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

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

    db.maternity_cases.belongsTo(db.doctors, {
      as: 'doctor',
      foreignKey: {
        name: 'doctorId',
      },
      constraints: false,
    });




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

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



  return maternity_cases;
};


