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

labour_start: {
        type: DataTypes.DATE,
      
      

      },

labour_end: {
        type: DataTypes.DATE,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  contraction_sessions.associate = (db) => {


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























































































    db.contraction_sessions.hasMany(db.contractions, {
      as: 'contractions_contraction_session',
      foreignKey: {
          name: 'contraction_sessionId',
      },
      constraints: false,
    });




























//end loop



    db.contraction_sessions.belongsTo(db.pregnancies, {
      as: 'pregnancy',
      foreignKey: {
        name: 'pregnancyId',
      },
      constraints: false,
    });




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

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



  return contraction_sessions;
};


