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

module.exports = (sequelize) => {
	const HistoryBudgeting = sequelize.define(
		"historybudgeting",
		{
			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
			action: { type: DataTypes.STRING(150), allowNull: true },
			date: { type: DataTypes.DATE, allowNull: true },

			//fk
			budgeting_id: {
				type: DataTypes.INTEGER,
				allowNull: true,
			},
		},
		{
			tableName: "historybudgetings",
			freezeTableName: true,
		}
	);

	/**
	 * Associates the HistoryBudgeting model with other models.
	 * @param {object} models - The models to associate with.
	 */
	HistoryBudgeting.associate = (models) => {
		/**
		 * Associates the HistoryBudgeting model with the AttendanceRequest model.
		 * Defines a many-to-one relationship between HistoryBudgeting and AttendanceRequest.
		 * @param {object} models - The models to associate with.
		 * @property {object} attendancerequest - The AttendanceRequest model associated with HistoryBudgeting.
		 */
		HistoryBudgeting.belongsTo(models.Budgeting, { foreignKey: "budgeting_id", as: "budgeting" });
	};

	return HistoryBudgeting;
};
