const { DataTypes } = require("sequelize");

module.exports = (sequelize) => {
	const BudgetingAccount = sequelize.define(
		"budgetingaccount",
		{
			id: {
				type: DataTypes.INTEGER,
				autoIncrement: true,
				primaryKey: true,
			},
			creation: { type: DataTypes.DATE, allowNull: false },
			modified: { type: DataTypes.DATE, allowNull: false },
			modified_by: { type: DataTypes.INTEGER, allowNull: false },
			owner: { type: DataTypes.INTEGER, allowNull: false },

			// main
			account: { type: DataTypes.STRING(50), allowNull: true },
            budget_amount: { type: DataTypes.FLOAT, allowNull: true },

			// fk
			budgeting_id: { type: DataTypes.INTEGER, allowNull: true },
			employee_id: { type: DataTypes.INTEGER, allowNull: true },
			department_id: { type: DataTypes.INTEGER, allowNull: true },
			company_id: { type: DataTypes.INTEGER, allowNull: true },
		},
		{
			tableName: "budgetingaccounts",
			freezeTableName: true,
		}
	);

	/**
	 * Associates the EmployeeGroup model with other models.
	 * @param {object} models - The models to associate with.
	 * @description
	 */
	BudgetingAccount.associate = (models) => {
		BudgetingAccount.belongsTo(models.Company, { as: "company", foreignKey: "company_id" });
		BudgetingAccount.belongsTo(models.Department, { as: "department", foreignKey: "department_id" });
		BudgetingAccount.belongsTo(models.Employee, { as: "employee", foreignKey: "employee_id" });
		BudgetingAccount.belongsTo(models.Budgeting, { as: "budgeting", foreignKey: "budgeting_id" });
	};

	return BudgetingAccount;
};
