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

module.exports = (sequelize) => {
    const HistoryLeaveApplication = sequelize.define(
        "historyleaveapplication",
        {
            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
            leaveapplication_id: {
                type: DataTypes.INTEGER,
                allowNull: true,
            },
        },
        {
            tableName: "historyleaveapplications",
            freezeTableName: true,
        }
    );

    /**
     * Associates the HistoryLeaveApplication model with other models.
     * @param {object} models - The models to associate with.
     */
    HistoryLeaveApplication.associate = (models) => {
         /**
         * Associates the HistoryLeaveApplication model with the Employee model.
         * Defines a many-to-one relationship between HistoryLeaveApplication and Employee.
         * @param {object} models - The models to associate with.
         * @property {object} employee - The Employee model associated with HistoryLeaveApplication.
         */
        HistoryLeaveApplication.belongsTo(models.LeaveApplication, {
            foreignKey: "leaveapplication_id",
            as: "leaveapplication",
        });
    };

    return HistoryLeaveApplication;
};
