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

module.exports = (sequelize) => {
    const HistoryAttendanceRequest = sequelize.define(
        "historyattendancerequest",
        {
            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
            attendancerequest_id: {
                type: DataTypes.INTEGER,
                allowNull: true,
            },
        },
        {
            tableName: "historyattendancerequests",
            freezeTableName: true,
        }
    );

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

    return HistoryAttendanceRequest;
};

