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

module.exports = (sequelize) => {
    const ImportLog = sequelize.define(
        "importlog",
        {
            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: true },
            owner: { type: DataTypes.INTEGER, allowNull: true },
            enabled: { type: DataTypes.BOOLEAN, allowNull: false }, 

            filename: { type: DataTypes.STRING, allowNull: true },
            is_imported: { type: DataTypes.BOOLEAN, allowNull: true },
            row_imported: { type: DataTypes.INTEGER, allowNull: true },
            status: { type: DataTypes.STRING, allowNull: true },

            // fk
            doctype_id: { type: DataTypes.INTEGER, allowNull: false },
        },
        {
            tableName: "importlogs",
            freezeTableName: true,
        }
    );

    ImportLog.associate = (models) => {
        ImportLog.belongsTo(models.DocType, { foreignKey: 'doctype_id', as: 'doctype' });
    };

    return ImportLog;
};
