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

module.exports = (sequelize) => {
    const AbsenceClarificationChild = sequelize.define(
        "absenceclarificationchild",
        {
            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 },

            date: { type: DataTypes.DATEONLY, allowNull: false },
            in_time: { type: DataTypes.TIME, allowNull: true },
            out_time: { type: DataTypes.TIME, allowNull: true },
            in_status: { type: DataTypes.STRING, allowNull: true },
            out_status: { type: DataTypes.STRING, allowNull: true },
            in_distance: { type: DataTypes.STRING, allowNull: true },
            out_distance: { type: DataTypes.STRING, allowNull: true },
            in_address: { type: DataTypes.TEXT, allowNull: true },
            out_address: { type: DataTypes.TEXT, allowNull: true },
            total_hour: { type: DataTypes.INTEGER, allowNull: true },
            in_latitude: { type: DataTypes.STRING, allowNull: true },
            in_longitude: { type: DataTypes.STRING, allowNull: true },
            out_latitude: { type: DataTypes.STRING, allowNull: true },
            out_longitude: { type: DataTypes.STRING, allowNull: true },
            reason: { type: DataTypes.TEXT, allowNull: true },
            notes: { type: DataTypes.TEXT, allowNull: true },
            explanation: { type: DataTypes.TEXT, allowNull: true },
            filename: { type: DataTypes.STRING, allowNull: true },
            status_absenceclarification: { type: DataTypes.BOOLEAN, allowNull: true },
            status_woriking_in_dayoff: { type: DataTypes.BOOLEAN, allowNull: true },

            // fk
            shifttype_id: {
                type: DataTypes.INTEGER,
                allowNull: true,
            },
            company_id: {
                type: DataTypes.INTEGER,
                allowNull: false,

            },
            employee_id: {
                type: DataTypes.INTEGER,
                allowNull: false,

            },
            attendance_id: {
                type: DataTypes.INTEGER,
                allowNull: true,
            },
            absenceclarification_id: {
                type: DataTypes.INTEGER,
                allowNull: false,
                references: {
                    model: 'absenceclarifications',
                    key: 'id'
                }
            },
        },
        {
            tableName: "absenceclarificationchilds",
            freezeTableName: true,
        }
    );

    /**
     * Associates the AbsenceClarificationChild model with other models.
     * @param {object} models - The models to associate with.
     */
    AbsenceClarificationChild.associate = (models) => {
        /**
         * Associates the AbsenceClarificationChild model with the AbsenceClarification model.
         * An AbsenceClarificationChild belongs to an AbsenceClarification.
         * @param {object} models - The models to associate with.
         */
        AbsenceClarificationChild.belongsTo(models.AbsenceClarification, { foreignKey: 'absenceclarification_id', as: 'absenceclarification' });
    };

    return AbsenceClarificationChild;
};

