#include "transfer_c_cpp.h"
#include <algorithm>

namespace utility {

	void DeviceCpp2C(const rtc::Device& f, AVDDevice& t) {
		strncpy(t.id, f.id.c_str(), std::min(sizeof(t.id), f.id.size()));
        strncpy(t.realid, f.realid.c_str(), std::min(sizeof(t.realid), f.realid.size()));
		strncpy(t.name, f.name.c_str(), std::min(sizeof(t.name), f.name.size()));
		t.status = f.status;
	}
	void DeviceC2Cpp(const AVDDevice& f, rtc::Device& t) {
		t.id = f.id;
        t.realid = f.realid;
		t.name = f.name;
		t.status = f.status;
	}
	void VideoCpp2C(const rtc::VideoDevice& f, AVDVideoDevice& t) {
		DeviceCpp2C(f, t.device);
		strncpy(t.description, f.description.c_str(), std::min(sizeof(t.description), f.description.size()));
		t.level = f.level;
		t.deviceQualities = f.deviceQualities.optionset;
		t.publishedQualities = f.publishedQualities.optionset;
	}
	void VideoC2Cpp(const AVDVideoDevice& f, rtc::VideoDevice& t) {
		DeviceC2Cpp(f.device, t);
		t.description = f.description;
		t.level = f.level;
        t.deviceQualities.optionset = f.deviceQualities;
        t.publishedQualities.optionset = f.publishedQualities;
	}

	void CameraCpp2C(const rtc::Camera& f, AVDCamera& t) {
		VideoCpp2C(f, t.videodevice);
		t.type = f.type;
	}

	void CameraC2Cpp(const AVDCamera& f, rtc::Camera& t) {
		VideoC2Cpp(f.videodevice, t);
		t.type = f.type;
	}

	void CapabilityC2Cpp(const AVDCameraCapability& f, rtc::CameraCapability& t) {
		t.width = f.width;
		t.height = f.height;
		t.maxFPS = f.maxFPS;
	}
	void CapabilityCpp2C(const rtc::CameraCapability& f, AVDCameraCapability& t) {
		t.width = f.width;
		t.height = f.height;
		t.maxFPS = f.maxFPS;
	}

	void AudioInfoC2Cpp(const AVDAudioInfo& f, rtc::AudioInfo& t) {
		t.input_level = f.input_level;
		t.output_level = f.output_level;
		for (uint32 i = 0; i < f.ncount; ++i) {
			t.active_streams.push_back(std::make_pair(rtc::UserId(f.userids[i]), f.levels[i]));
		}
	}
    void NetStatsC2Cpp(const AVDNetworkStats& f, rtc::NetworkStats& t){
        t.bps_received = f.bps_received;
        t.bps_sent = f.bps_sent;
        t.lostpercent = f.lostpercent;
        t.lostpercent_received = f.lostpercent_received;
        t.lostpercent_sent = f.lostpercent_sent;
        t.bytes_received = f.bytes_received;
        t.bytes_sent = f.bytes_sent;
        t.packets_lost =  f.packets_lost;
        t.packets_lost_received = f.packets_lost_received;
        t.packets_lost_sent = f.packets_lost_sent;
        t.packets_received = f.packets_received;
        t.packets_sent = f.packets_sent;
    }
	void MediaStatsC2Cpp(const AVDMediaStats& f, rtc::MediaStats& t) {

        NetStatsC2Cpp(f.netstats,t);
		t.audio_input_level = f.audio_input_level;
		t.media_type = f.media_type;
		t.codec_name = f.codec_name;
		t.audio_output_level = f.audio_output_level;
		t.frame_width = f.frame_width;
		t.frame_height = f.frame_height;
		t.frame_rate = f.frame_rate;
	}
}
