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

account_code: {
        type: DataTypes.TEXT,
      
      

      },

name: {
        type: DataTypes.TEXT,
      
      

      },

account_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"asset",


"liability",


"equity",


"revenue",


"expense",


"cogs"

        ],

      },

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

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

  gl_accounts.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity









































    db.gl_accounts.hasMany(db.journal_lines, {
      as: 'journal_lines_gl_account',
      foreignKey: {
          name: 'gl_accountId',
      },
      constraints: false,
    });





//end loop






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

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



  return gl_accounts;
};


