// Created with MonoDevelop
//
//    QuickStep: Acquire, view and identify spectra 
//    Copyright (C) 2017 Thomas Klose & Torsten Schache, Hiperscan GmbH Dresden, Germany
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.


using System;
using Hiperscan.Common.I18n;
using Hiperscan.PdfLib;
using Hiperscan.Spectroscopy.IdentModule;

namespace Hiperscan.Extensions.ApoIdent.Report
{

    public class Germany : GermanTemplate
    {
        public Germany(ReportInfo  report_info) : base(report_info)
        {
        }

        protected override void CreateHeader()
        {
            this.Layout.SetFont(PdfFontTypes.HELVETICA, 14, PdfColors.Black);


            if (this.ReportInfo.ProtocolType != ProtocolType.ApoIdent && Locale.Language == "de")
            {
                this.Layout.Feed(11);
                this.Layout.AddParagraph("NIR Messprotokoll", PdfTextAlignments.Center);
                this.Layout.Feed(13);
            }
            else
            {
                this.Layout.SetFont(PdfFontTypes.HELVETICA, 14, PdfColors.Black);
                this.Layout.AddParagraph("Prüfprotokoll zur Feststellung der Identität\n von Ausgangsstoffen (§§ 6,11 ApBetrO)",                            PdfTextAlignments.Center);    
                this.Layout.Feed(22);                    
            }
        }

        protected override bool CreateSubstanceProperties()
        {
            if (base.CreateSubstanceProperties() == false)
                return false;

            if (this.ReportInfo.ProtocolType != ProtocolType.ApoIdent)
                return true;

            if (this.ReportInfo.BAKMrkingActivated == false)
                return true;

            if (this.State.CurrentPage > 1)
                return true;

            this.Layout.XPosition = 0;
            if (this.Layout.AddParagraph("BAK-Kennzeichnung:") == false)
                return false;
            this.Layout.XPosition = this.ReferenceTabIndent;

            double radius = this.ReferenceFontSize / 3;

            double line_width = 0.1;
            PdfPoint center = null;
            int color = 0;
            double y_pos = this.Layout.YPosition + 1.6 * radius;
            double x_pos = this.Layout.XPosition + radius;

            switch (this.ReportInfo.BAKMarking)
            {
                case Spectroscopy.IdentModule.BAKMarkingState.None:
                    this.Text = "k.A.";
                    if (this.Layout.AddParagraph(this.Text) == false)
                        return false;
                    break;

                case Spectroscopy.IdentModule.BAKMarkingState.Red:
                    center = new PdfPoint(x_pos, y_pos);

                    color = 0x00F20000;
                    if (this.Layout.AddCircle(center,
                                          radius,
                                          line_width,
                                          PdfColors.Black,
                                           color,
                                           false) == false)
                    {
                        return false;
                    }
                    break;

                default:

                    if (this.ReportInfo.BAKMarking.HasFlag(BAKMarkingState.Yellow))
                    {
                        center = new PdfPoint(x_pos, y_pos);
                        color = 0x00F2F200;

                        if (this.Layout.AddCircle(center,
                                              radius,
                                              line_width,
                                              PdfColors.Black,
                                               color,
                                               false) == false)
                        {
                            return false;
                        }
                    }

                    if (this.ReportInfo.BAKMarking.HasFlag(BAKMarkingState.Blue))
                    {
                        x_pos += 2.7 * radius;
                        center = new PdfPoint(x_pos, y_pos);
                        color = 0x000000F2;

                        if (this.Layout.AddCircle(center,
                                              radius,
                                              line_width,
                                              PdfColors.Black,
                                               color,
                                               false) == false)
                        {
                            return false;
                        }
                    }

                    if (this.ReportInfo.BAKMarking.HasFlag(BAKMarkingState.Orange))
                    {
                        x_pos += 2.7 * radius;
                        center = new PdfPoint(x_pos, y_pos);
                        color = 0x00F29C00;

                        if (this.Layout.AddCircle(center,
                                              radius,
                                              line_width,
                                              PdfColors.Black,
                                               color,
                                               false) == false)
                        {
                            return false;
                        }
                    }

                    break;
            }

            this.Layout.Feed(this.Layout.ParagraphBoundingBox.Height + this.ReferenceLineDistance);
            return true;
        }
    }
}

