//..............................................................................
//
// Ninja log - writer
//

import "log_RecordCode.jnc"

namespace log {

//! \addtogroup api-log
//! @{

//..............................................................................

opaque class Writer
{
	write(
		uint64_t timestamp,
		uint64_t recordCode,
		void const* p,
		size_t size
		);

	// when jnccdecl vararg is functional, we can remove this overload

	write(
		uint64_t timestamp,
		uint64_t recordCode,
		void const* p1,
		size_t size1,
		void const* p2,
		size_t size2
		);

	write(
		uint64_t recordCode,
		void const* p,
		size_t size
		)
	{
		write(sys.getPreciseTimestamp(), recordCode, p, size);
	}

	write(
		uint64_t recordCode,
		void const* p1,
		size_t size1,
		void const* p2,
		size_t size2
		)
	{
		write(sys.getPreciseTimestamp(), recordCode, p1, size1, p2, size2);
	}

	write(
		uint64_t timestamp,
		uint64_t recordCode
		)
	{
		write(timestamp, recordCode, null, 0);
	}

	write(uint64_t recordCode)
	{
		write(sys.getPreciseTimestamp(), recordCode, null, 0);
	}

	write(
		uint64_t timestamp,
		uint64_t recordCode,
		char const* p
		)
	{
		write(timestamp, recordCode, p, strlen(p));
	}

	write(
		uint64_t recordCode,
		char const* p
		)
	{
		write(sys.getPreciseTimestamp(), recordCode, p, strlen(p));
	}

	write(
		uint64_t timestamp,
		uint64_t recordCode,
		std.Error const* error
		)
	{
		write(timestamp, recordCode, error, error.m_size);
	}

	write(
		uint64_t recordCode,
		std.Error const* error
		)
	{
		write(sys.getPreciseTimestamp(), recordCode, error, error.m_size);
	}

	writeLastError(
		uint64_t timestamp,
		uint64_t recordCode
		)
	{
		write(timestamp, recordCode, std.getLastError());
	}

	writeLastError(uint64_t recordCode)
	{
		write(sys.getPreciseTimestamp(), recordCode, std.getLastError());
	}

	retroColorize(
		intptr_t retroOffset,
		size_t length,
		ui.TextAttr attr,
		RetroColorizeFlags flags = 0
		)
	{
		RetroColorizeParams params;
		params.m_retroOffset = retroOffset;
		params.m_length = length;
		params.m_attr = attr;
		params.m_flags = flags;

		write(StdRecordCode.RetroColorize, &params, sizeof(params));
	}

	retroColorize(
		intptr_t retroOffset,
		size_t length,
		uint_t color
		)
	{
		ui.TextAttr attr;
		attr.m_textColor = color;
		attr.m_backColor = ui.ColorFlags.Transparent;

		retroColorize(retroOffset, length, attr);
	}
}

//..............................................................................

//! @}

} // namespace log
