// Created with MonoDevelop
//
//    QuickStep: Acquire, view and identify spectra 
//    Copyright (C) 2024 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 System.Collections.Generic;
using Hiperscan.AnalysisModule.Identification;
using Hiperscan.PdfLib;

namespace Hiperscan.ApoIdentCore.Reporting.Protocol.SubstanceProperties
{
    public class DeDESubstanceProperties : CommonSubstanceProperties
    {
        protected override void Init(PdfArgs args)
        {
            base.Init(args);
            this.BakMarkingLabel = String.Empty;
            if (this.Info.BAKMarkingActivated)
                this.BakMarkingLabel = "BAK-Kennzeichnung:";
        }

        protected override bool DrawRow3Right()
        {
            this.Layout.XPosition = this.IndentX2;
            if (this.Layout.AddParagraph(this.BakMarkingLabel) == false)
                return false;

            this.Layout.XPosition = IndentX3;
            return this.DrawBakMarking(this.Layout.XPosition, this.Layout.YPosition, this.Args.ReferenceFontSize);
        }

        private bool DrawBakMarking(double x_pos_ref, double y_pos_ref, double ref_font_size)
        {
            if (this.Info.BAKMarkingActivated == false)
                return true;

            double radius = ref_font_size / 3;
            double line_width = 0.1;
            PdfPoint center = null;
            int color = 0;

            double y_pos = y_pos_ref + 1.8 * radius;
            double x_pos = x_pos_ref + radius;

            switch (this.Info.BAKMarking)
            {
                case 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.Info.BAKMarking.HasFlag(BAKMarkingState.Yellow))
                    {
                        center = new PdfPoint(x_pos, y_pos);
                        color = 0x00F2F200;
                        x_pos += 2.7 * radius;

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

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

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

                    if (this.Info.BAKMarking.HasFlag(BAKMarkingState.Orange))
                    {
                        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;
            }

            return true;
        }

        protected override List<string> InitLabelColumn()
        {
            List<string> tmp = base.InitLabelColumn();
            tmp.Add(this.BakMarkingLabel);
            return tmp;
        }

        protected string BakMarkingLabel { get; set; }
    }
}
