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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"started",


"completed",


"failed"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

finished_at: {
        type: DataTypes.DATE,
      
      

      },

created_trades: {
        type: DataTypes.INTEGER,
      
      

      },

updated_trades: {
        type: DataTypes.INTEGER,
      
      

      },

skipped_trades: {
        type: DataTypes.INTEGER,
      
      

      },

error_details: {
        type: DataTypes.TEXT,
      
      

      },

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

  trade_sync_runs.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.trade_sync_runs.belongsTo(db.broker_connections, {
      as: 'broker_connection',
      foreignKey: {
        name: 'broker_connectionId',
      },
      constraints: false,
    });




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

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



  return trade_sync_runs;
};


