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

report_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"compliance_health",


"upcoming_obligations",


"missed_deadlines",


"risk_analysis"

        ],

      },

format: {
        type: DataTypes.ENUM,
      
      

        values: [

"pdf",


"excel"

        ],

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

generated_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"completed",


"failed"

        ],

      },

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

  report_exports.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.report_exports.belongsTo(db.companies, {
      as: 'company',
      foreignKey: {
        name: 'companyId',
      },
      constraints: false,
    });

    db.report_exports.belongsTo(db.users, {
      as: 'requested_by',
      foreignKey: {
        name: 'requested_byId',
      },
      constraints: false,
    });

    db.report_exports.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });



    db.report_exports.hasMany(db.file, {
      as: 'report_file',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.report_exports.getTableName(),
        belongsToColumn: 'report_file',
      },
    });


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

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



  return report_exports;
};


