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

code: {
        type: DataTypes.TEXT,
      
      

      },

name: {
        type: DataTypes.TEXT,
      
      

      },

opening_balance: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

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

  cash_boxes.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.cash_boxes.belongsTo(db.businesses, {
      as: 'business',
      foreignKey: {
        name: 'businessId',
      },
      constraints: false,
    });

    db.cash_boxes.belongsTo(db.branches, {
      as: 'branch',
      foreignKey: {
        name: 'branchId',
      },
      constraints: false,
    });

    db.cash_boxes.belongsTo(db.currencies, {
      as: 'currency',
      foreignKey: {
        name: 'currencyId',
      },
      constraints: false,
    });




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

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



  return cash_boxes;
};


