#pragma once

#include <softbus_bus/Bus.h>

#include <fstream>
#include <mutex>
#include <string>

namespace softbus::storage {

class StorageService {
public:
    explicit StorageService(std::string dataDir = "data/logs");

    void attachBus(softbus::bus::Bus* bus);
    bool open();

private:
    void onBusMessage(const softbus::bus::BusMessage& message);
    void appendLine(const std::string& fileName, const std::string& line);

    std::string dataDir_;
    softbus::bus::Bus* bus_{nullptr};
    softbus::bus::Bus::SubscriptionId dataSub_{0};
    softbus::bus::Bus::SubscriptionId ackSub_{0};
    softbus::bus::Bus::SubscriptionId eventSub_{0};
    std::mutex mutex_;
    std::ofstream timeseries_;
    std::ofstream commandLog_;
    std::ofstream eventLog_;
};

} // namespace softbus::storage
