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

attachment_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"screenshot",


"chart",


"statement",


"other"

        ],

      },

caption: {
        type: DataTypes.TEXT,
      
      

      },

captured_at: {
        type: DataTypes.DATE,
      
      

      },

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

  trade_attachments.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_attachments.belongsTo(db.trades, {
      as: 'trade',
      foreignKey: {
        name: 'tradeId',
      },
      constraints: false,
    });



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

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


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

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



  return trade_attachments;
};


