'use strict';
const {
  Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  class CashDrawerActivity extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      // define association here
      CashDrawerActivity.belongsTo(models.User, { foreignKey: 'performedBy', as: 'user' });
      CashDrawerActivity.belongsTo(models.Register, { foreignKey: 'registerId', as: 'register' });

      // Association with CashDrawerSession
      CashDrawerActivity.belongsTo(models.CashDrawerSession, {
        foreignKey: 'sessionId',
        as: 'session'
      });

        // Association with Store
      CashDrawerActivity.belongsTo(models.Store, {
        foreignKey: 'storeId',
        as: 'store'
      });
    }
  }
  CashDrawerActivity.init({
    registerId: DataTypes.INTEGER,
    storeId:DataTypes.INTEGER,
    sessionId: DataTypes.INTEGER,
    activityType: DataTypes.STRING,
    amount: DataTypes.DECIMAL,
    balanceBefore:DataTypes.DECIMAL,
    balanceAfter:DataTypes.DECIMAL,
    reason: DataTypes.TEXT,
    performedBy: DataTypes.INTEGER,
    performedAt: DataTypes.DATE
  }, {
    sequelize,
    modelName: 'CashDrawerActivity',
  });
  return CashDrawerActivity;
};