#include "transmission.h"

#include <iostream>

static std::vector<bool> message;
const int MAX_M = 100000;

std::vector<bool> transmit_1(const std::vector<bool>& data, int d) {
#ifdef STJO
	std::cout << "to send:" << std::endl;
	for(auto x : data) std::cout << x;
	std::cout << std::endl;
#endif

	const int N = data.size();
	//const int coef = (d * N > MAX_M ? MAX_M / N : d);
	const int coef = 3; //(d * N > MAX_M ? MAX_M / N : d);

	message.resize(N * coef);

	for(int i = 0;i < message.size();i ++) {
		message[i] = data[i / coef] ;
	}

#ifdef STJO
	std::cout << "sending:" << std::endl;
	for(auto x : message) std::cout << x;
	std::cout << std::endl;
#endif

    return message;
}

std::vector<bool> transmit_2(const std::vector<bool>& data, int d)
{
#ifdef STJO
	std::cout << "to send:" << std::endl;
	for(auto x : data) std::cout << x;
	std::cout << std::endl;
#endif

	const int N = data.size();

	const int blockSize = 15;
	const int padSize = 15;
	int idx = 0;

	message.resize(MAX_M);
	int cnt = 0;
	for(int i = 0;i < N;i ++) {
		message[idx ++] = data[i];
		// todo break if no more
		if((i+1) % blockSize == 0) {
#ifdef STJO
			for(int _ = i - blockSize + 1;_ <= i;_ ++) std::cout << data[_];
			std::cout << std::endl;
			std::cout << "adding pad " << (cnt++) << ' ' << idx << std::endl;
#endif
			for(int p = 0;p < padSize;p ++) message[idx ++] = !data[i];
			//std::cout << idx << std::endl;
			//std::cout << "----\n";
		}
	}

	message.resize(idx);

#ifdef STJO
	std::cout << "sending:" << std::endl;
	for(auto x : message) std::cout << x;
	std::cout << std::endl;
#endif

    return message;
}

std::vector<bool> transmit(const std::vector<bool>& data, int d) {
	return transmit_2(data, d);
}
