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

group_code: {
        type: DataTypes.TEXT,
      
      

      },

item_code: {
        type: DataTypes.TEXT,
      
      

      },

description_text: {
        type: DataTypes.TEXT,
      
      

      },

country: {
        type: DataTypes.TEXT,
      
      

      },

registration_number: {
        type: DataTypes.TEXT,
      
      

      },

value_previous_year: {
        type: DataTypes.DECIMAL,
      
      

      },

value_current_year: {
        type: DataTypes.DECIMAL,
      
      

      },

disposed_in_year: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

disposal_value: {
        type: DataTypes.DECIMAL,
      
      

      },

buyer_document: {
        type: DataTypes.TEXT,
      
      

      },

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

  assets.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.assets.belongsTo(db.declarations, {
      as: 'declaration',
      foreignKey: {
        name: 'declarationId',
      },
      constraints: false,
    });

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




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

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



  return assets;
};


