#pragma once

#include "binarystore.hpp"
#include "binarystore_interface.hpp"
#include "sys_file.hpp"

#include <memory>
#include <optional>
#include <string>
#include <vector>

#include <gmock/gmock.h>

using ::testing::Invoke;

namespace binstore
{

class MockBinaryStore : public BinaryStoreInterface
{
  public:
    MockBinaryStore(const std::string& baseBlobId,
                    std::unique_ptr<SysFile> file,
                    std::optional<uint32_t> maxSize = std::nullopt) :
        real_store_(baseBlobId, std::move(file), maxSize)
    {
        // Implemented calls in BinaryStore will be directed to the real object.
        ON_CALL(*this, getBaseBlobId)
            .WillByDefault(Invoke(&real_store_, &BinaryStore::getBaseBlobId));
        ON_CALL(*this, getBlobIds)
            .WillByDefault(Invoke(&real_store_, &BinaryStore::getBlobIds));
        ON_CALL(*this, openOrCreateBlob)
            .WillByDefault(
                Invoke(&real_store_, &BinaryStore::openOrCreateBlob));
        ON_CALL(*this, close)
            .WillByDefault(Invoke(&real_store_, &BinaryStore::close));
        ON_CALL(*this, read)
            .WillByDefault(Invoke(&real_store_, &BinaryStore::read));
        ON_CALL(*this, write)
            .WillByDefault(Invoke(&real_store_, &BinaryStore::write));
        ON_CALL(*this, commit)
            .WillByDefault(Invoke(&real_store_, &BinaryStore::commit));
        ON_CALL(*this, stat)
            .WillByDefault(Invoke(&real_store_, &BinaryStore::stat));
    }
    MOCK_CONST_METHOD0(getBaseBlobId, std::string());
    MOCK_CONST_METHOD0(getBlobIds, std::vector<std::string>());
    MOCK_METHOD2(openOrCreateBlob, bool(const std::string&, uint16_t));
    MOCK_METHOD1(deleteBlob, bool(const std::string&));
    MOCK_METHOD2(read, std::vector<uint8_t>(uint32_t, uint32_t));
    MOCK_METHOD2(write, bool(uint32_t, const std::vector<uint8_t>&));
    MOCK_METHOD0(commit, bool());
    MOCK_METHOD0(close, bool());
    MOCK_METHOD1(stat, bool(blobs::BlobMeta* meta));

    std::vector<uint8_t> readBlob(const std::string& blobId) const override
    {
        return real_store_.readBlob(blobId);
    }

  private:
    BinaryStore real_store_;
};

} // namespace binstore
