'use strict';
const {
  Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  class CashDrawerSession 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
      CashDrawerSession.belongsTo(models.Register, { foreignKey: 'registerId', as: 'register' });
      CashDrawerSession.belongsTo(models.User, { foreignKey: 'openedBy', as: 'openedUser' });
      CashDrawerSession.belongsTo(models.User, { foreignKey: 'closedBy', as: 'closedUser' });
      CashDrawerSession.belongsTo(models.Store, { foreignKey: 'storeId', as: 'store' });
    }
  }
  CashDrawerSession.init({
    registerId: DataTypes.INTEGER,
    storeId: DataTypes.INTEGER,
    openedBy: DataTypes.INTEGER,
    closedBy: DataTypes.INTEGER,
    openedAt: DataTypes.DATE,
    closedAt: DataTypes.DATE,
    openingCash: DataTypes.DECIMAL,
    closingCash: DataTypes.DECIMAL,
    expectedCash: DataTypes.DECIMAL,
    variance: DataTypes.DECIMAL,
    totalSales: DataTypes.DECIMAL,
    totalRefunds: DataTypes.DECIMAL,
    cashIn: DataTypes.DECIMAL,
    cashOut: DataTypes.DECIMAL,
    notes: DataTypes.TEXT
  }, {
    sequelize,
    modelName: 'CashDrawerSession',
  });
  return CashDrawerSession;
};