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

title: {
        type: DataTypes.TEXT,
      
      

      },

report_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"monthly",


"weekly",


"custom",


"strategy_comparison",


"account_comparison"

        ],

      },

period_start_at: {
        type: DataTypes.DATE,
      
      

      },

period_end_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"generating",


"ready",


"failed"

        ],

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

generated_at: {
        type: DataTypes.DATE,
      
      

      },

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

  pdf_reports.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.pdf_reports.belongsTo(db.trading_accounts, {
      as: 'trading_account',
      foreignKey: {
        name: 'trading_accountId',
      },
      constraints: false,
    });



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


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

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



  return pdf_reports;
};


