// SPDX-License-Identifier: GPL-2.0-or-later
// SPDX-FileCopyrightText: 2025 Hannah von Reth <h.vonreth@opencloud.eu>

#pragma once

#include "common/syncjournalfilerecord.h"
#include "networkjobs/getfilejob.h"


#include <QIODevice>
#include <QObject>

namespace OCC {
class Vfs;

class QSFERA_SYNC_EXPORT HydrationJob : public QObject
{
    Q_OBJECT
public:
    HydrationJob(Vfs *vfs, const QByteArray &fileId, std::unique_ptr<QIODevice> &&device, QObject *parent);

    void start();
    void abort();

    // In case the device to write to is a file, it can be passed here to the result slots
    void setTargetFile(const QString& fileName);
    QString targetFileName() const;

    Vfs *vfs() const;

    SyncJournalFileRecord record() const;

    QByteArray fileId() const { return _fileId; }

Q_SIGNALS:
    void finished();
    void error(const QString &error);

private:
    Vfs *_vfs;
    QByteArray _fileId;
    std::unique_ptr<QIODevice> _device;
    QString _fileName;
    SyncJournalFileRecord _record;
    GETFileJob *_job = nullptr;
};
}
