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

period_start: {
        type: DataTypes.DATE,
      
      

      },

period_end: {
        type: DataTypes.DATE,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

breakthrough_bleeding: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  menstrual_cycles.associate = (db) => {


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













































































    db.menstrual_cycles.hasMany(db.menstrual_day_logs, {
      as: 'menstrual_day_logs_cycle',
      foreignKey: {
          name: 'cycleId',
      },
      constraints: false,
    });






































//end loop



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




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

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



  return menstrual_cycles;
};


