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

last_menstrual_period_date: {
        type: DataTypes.DATE,
      
      

      },

conception_date: {
        type: DataTypes.DATE,
      
      

      },

due_date: {
        type: DataTypes.DATE,
      
      

      },

delivery_date: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pregnant",


"postpartum",


"ended"

        ],

      },

birth_plan: {
        type: DataTypes.TEXT,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  pregnancies.associate = (db) => {


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
















































































    db.pregnancies.hasMany(db.pregnancy_symptom_logs, {
      as: 'pregnancy_symptom_logs_pregnancy',
      foreignKey: {
          name: 'pregnancyId',
      },
      constraints: false,
    });


    db.pregnancies.hasMany(db.breastfeeding_logs, {
      as: 'breastfeeding_logs_pregnancy',
      foreignKey: {
          name: 'pregnancyId',
      },
      constraints: false,
    });


    db.pregnancies.hasMany(db.formula_feeding_logs, {
      as: 'formula_feeding_logs_pregnancy',
      foreignKey: {
          name: 'pregnancyId',
      },
      constraints: false,
    });


    db.pregnancies.hasMany(db.baby_metrics, {
      as: 'baby_metrics_pregnancy',
      foreignKey: {
          name: 'pregnancyId',
      },
      constraints: false,
    });


    db.pregnancies.hasMany(db.epds_assessments, {
      as: 'epds_assessments_pregnancy',
      foreignKey: {
          name: 'pregnancyId',
      },
      constraints: false,
    });


    db.pregnancies.hasMany(db.kick_counts, {
      as: 'kick_counts_pregnancy',
      foreignKey: {
          name: 'pregnancyId',
      },
      constraints: false,
    });


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





























//end loop



    db.pregnancies.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });




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

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



  return pregnancies;
};


