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

investment_name: {
        type: DataTypes.TEXT,
      
      

      },

instrument_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"equity",


"debt",


"revenue_share",


"grant",


"other"

        ],

      },

amount_committed: {
        type: DataTypes.DECIMAL,
      
      

      },

amount_funded: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

committed_at: {
        type: DataTypes.DATE,
      
      

      },

funded_at: {
        type: DataTypes.DATE,
      
      

      },

investment_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"proposed",


"active",


"completed",


"canceled"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  investments.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.investments.belongsTo(db.tenants, {
      as: 'investor_tenant',
      foreignKey: {
        name: 'investor_tenantId',
      },
      constraints: false,
    });

    db.investments.belongsTo(db.tenants, {
      as: 'farm_tenant',
      foreignKey: {
        name: 'farm_tenantId',
      },
      constraints: false,
    });

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




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

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



  return investments;
};


