//.............................................................................
//
// Serial Monitor log packet declarations and representer
//

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

enum SerialMonLogRecordCode
{
	CaptureStarted = 0x100, // don't mix with SerialLogRecordCode
	CaptureStopped,
	CaptureError,
	DeviceOpened, 
	DeviceClosed,
}

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

bool representSerialMonLog  (
	log.RepresenterTarget* target,
	uint_t recordCode,
	void const* p,
	size_t size,
	uint_t foldFlags
	)
{
	switch (recordCode)
	{
	case SerialMonLogRecordCode.CaptureStarted:
		char const* name = (char const*) p;
		target.m_lineAttr.m_iconIdx = log.StdLogIcon.Play;
		target.m_lineAttr.m_backColor = log.StdLogColor.Start;
		target.addHyperText ($"Capture started on port \e[34m$name");
		break;

	case SerialMonLogRecordCode.CaptureStopped:
		target.m_lineAttr.m_iconIdx = log.StdLogIcon.Pause;
		target.m_lineAttr.m_backColor = log.StdLogColor.Stop;
		target.addHyperText ("Capture stopped");
		break;

	case SerialMonLogRecordCode.CaptureError:
		std.Error const* error = (std.Error const*) p;
		target.m_lineAttr.m_iconIdx = log.StdLogIcon.Error;
		target.m_lineAttr.m_backColor = log.StdLogColor.Error;
		target.addHyperText ($"Unable to start capture: $(error.m_description)");
		break;

	case SerialMonLogRecordCode.DeviceOpened:
		target.m_lineAttr.m_iconIdx = log.StdLogIcon.Info;
		target.m_lineAttr.m_backColor = log.StdLogColor.Info;
		target.addHyperText ("Port opened");
		break;

	case SerialMonLogRecordCode.DeviceClosed:
		target.m_lineAttr.m_iconIdx = log.StdLogIcon.Info;
		target.m_lineAttr.m_backColor = log.StdLogColor.Info;
		target.addHyperText ("Port closed");
		break;

	default:
		return representSerialLog (target, recordCode, p, size, foldFlags);
	}

	return true;
}

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