/**********************************************************************
 * LeechCraft - modular cross-platform feature rich internet client.
 * Copyright (C) 2006-2014  Georg Rudoy
 *
 * Boost Software License - Version 1.0 - August 17th, 2003
 *
 * Permission is hereby granted, free of charge, to any person or organization
 * obtaining a copy of the software and accompanying documentation covered by
 * this license (the "Software") to use, reproduce, display, distribute,
 * execute, and transmit the Software, and to prepare derivative works of the
 * Software, and to permit third-parties to whom the Software is furnished to
 * do so, all subject to the following:
 *
 * The copyright notices in the Software and this entire statement, including
 * the above license grant, this restriction and the following disclaimer,
 * must be included in all copies of the Software, in whole or in part, and
 * all derivative works of the Software, unless such copies or derivative
 * works are solely in the form of machine-executable object code generated by
 * a source language processor.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
 * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
 * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 **********************************************************************/

#pragma once

#include <memory>
#include <poppler-annotation.h>
#include <interfaces/monocle/iannotation.h>

namespace Poppler
{
	class Annotation;
	class TextAnnotation;
}

namespace LC
{
namespace Monocle
{
namespace PDF
{
	class Document;

	IAnnotation_ptr MakeAnnotation (Document*, Poppler::Annotation*);

	template<typename T>
	class AnnotationBase : public T
	{
		const std::unique_ptr<Poppler::Annotation> Ann_;
	public:
		AnnotationBase (Poppler::Annotation *ann)
		: Ann_ { ann }
		{
		}

		virtual ~AnnotationBase () {}

		QString GetAuthor () const override
		{
			return Ann_->author ();
		}

		QDateTime GetDate () const override
		{
			return Ann_->creationDate ();
		}

		QRectF GetBoundary () const override
		{
			return Ann_->boundary ();
		}

		QString GetText () const override
		{
			return Ann_->contents ();
		}
	};

	class TextAnnotation : public AnnotationBase<ITextAnnotation>
	{
		Poppler::TextAnnotation * const TextAnn_;
	public:
		TextAnnotation (Poppler::TextAnnotation*);

		AnnotationType GetAnnotationType () const override;
		bool IsInline () const override;
	};

	class HighlightAnnotation : public AnnotationBase<IHighlightAnnotation>
	{
		Poppler::HighlightAnnotation * const HighAnn_;
	public:
		HighlightAnnotation (Poppler::HighlightAnnotation*);

		AnnotationType GetAnnotationType () const override;
		QList<QPolygonF> GetPolygons () const override;
	};

	class LinkAnnotation : public AnnotationBase<ILinkAnnotation>
	{
		Poppler::LinkAnnotation * const LinkAnn_;
		ILink_ptr Link_;
	public:
		LinkAnnotation (Document*, Poppler::LinkAnnotation*);

		AnnotationType GetAnnotationType () const override;
		ILink_ptr GetLink () const override;
	};

	class CaretAnnotation : public AnnotationBase<ICaretAnnotation>
	{
	public:
		CaretAnnotation (Poppler::CaretAnnotation*);

		AnnotationType GetAnnotationType () const override;
	};
}
}
}
