'use strict';
const { Model } = require('sequelize');
const { defaultKeys, modelDefaults, actionUsers } = require('../sequelize/defaults');
module.exports = (sequelize, DataTypes) => {
  class Expenses extends Model {
    static associate(models) {
      actionUsers(Expenses, models);
      Expenses.belongsTo(models.Branch, {
        targetKey: "branch_id",
        foreignKey: "branch_id",
        as: "branches",
      });
      Expenses.belongsTo(models.ItemCategory, {
        targetKey: "item_category_id",
        foreignKey: "item_category_id",
        as: "itemCategories",
      });
      Expenses.belongsTo(models.User, {
        targetKey: "user_id",
        foreignKey: "user_id",
        as: "usersDetails",
      });
    }
  }

  Expenses.init({
    ...defaultKeys("expenses_id"),
    tbl_ref_id: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    expenses_amount: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    expenses_date: {
      type: DataTypes.DATEONLY,
      allowNull: false,
    },
    expenses_descp: {
      type: DataTypes.STRING,
      allowNull: true,
    },
  }, modelDefaults(sequelize, 'expenses'));
  return Expenses;
};