#pragma once

#include "quicr/QuicrConnection.hpp"
#include "quicr/QuicrError.hpp"
#include "tl/expected.hpp"

namespace tw::net::quicr {

class QuicrStream {
    QuicrConnection* m_connection;
    bool m_is_reliable;

public:
    QuicrStream(QuicrConnection* connection, bool is_reliable);

    tl::expected<size_t, QuicrError> write(std::span<std::byte> data) {
        auto send_r = m_connection->send_message(data, m_is_reliable);
        if(!send_r) {
            return tl::make_unexpected(send_r.error());
        }

        return data.size();
    }

    tl::expected<size_t, QuicrError> read_into(std::span<std::byte> target) {
        auto read_r = m_connection->read_into(target);
        if(!read_r) {
            return tl::make_unexpected(read_r.error());
        }

        return *read_r;
    }
};

}
