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

export_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"doctor_report_pdf",


"lab_results_pdf",


"medication_card_pdf",


"emergency_card_pdf",


"vaccination_record_pdf",


"fitness_report_pdf",


"nutrition_report_pdf",


"menstrual_cycle_report_pdf",


"mental_health_report_pdf",


"sleep_report_pdf",


"comprehensive_health_summary_pdf",


"raw_backup_json",


"section_csv"

        ],

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

range_start: {
        type: DataTypes.DATE,
      
      

      },

range_end: {
        type: DataTypes.DATE,
      
      

      },

included_sections: {
        type: DataTypes.TEXT,
      
      

      },

chief_complaint: {
        type: DataTypes.TEXT,
      
      

      },

questions_for_doctor: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"completed",


"failed"

        ],

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

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

  export_jobs.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.export_jobs.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });




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

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



  return export_jobs;
};


