#ifndef __HELPERS_H__
#define __HELPERS_H__

#include <memory>
#include <optional>
#include <rtc/rtc.hpp>
#include <shared_mutex>

template <class T>
std::weak_ptr<T> make_weak_ptr(std::shared_ptr<T> ptr) {
    return ptr;
}

uint64_t currentTimeInMicroSeconds();

struct ClientTrackData {
    std::shared_ptr<rtc::Track> track;
    std::shared_ptr<rtc::RtcpSrReporter> sender;
};

class Client {
public:
    enum class State {
        Waiting,
        WaitingForVideo,
        WaitingForAudio,
        Ready,
    };
    Client(std::shared_ptr<rtc::PeerConnection> pc);
    State state() const;
    void setState(State state);
    std::shared_ptr<rtc::PeerConnection> peerConnection() const;
    std::optional<std::shared_ptr<ClientTrackData>> video;
    std::optional<std::shared_ptr<rtc::DataChannel>> dataChannel;

private:
    mutable std::shared_mutex m_mutex;
    State m_state = State::Waiting;
    std::shared_ptr<rtc::PeerConnection> m_peerConnection;
};

struct ClientTrack {
    std::string id;
    std::shared_ptr<ClientTrackData> trackData;
    ClientTrack(std::string id, std::shared_ptr<ClientTrackData> trackData);
};

#endif // __HELPERS_H__