// 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;
using Hiperscan.AnalysisModule.Identification;
using Hiperscan.ApoIdentCore.Reporting.Protocol.AdditionalText;
using Hiperscan.ApoIdentCore.Reporting.Protocol.Address;
using Hiperscan.ApoIdentCore.Reporting.Protocol.Advice;
using Hiperscan.ApoIdentCore.Reporting.Protocol.CertificateCheck;
using Hiperscan.ApoIdentCore.Reporting.Protocol.Comment;
using Hiperscan.ApoIdentCore.Reporting.Protocol.FinalResult;
using Hiperscan.ApoIdentCore.Reporting.Protocol.Footer;
using Hiperscan.ApoIdentCore.Reporting.Protocol.Graphics;
using Hiperscan.ApoIdentCore.Reporting.Protocol.Header;
using Hiperscan.ApoIdentCore.Reporting.Protocol.Method;
using Hiperscan.ApoIdentCore.Reporting.Protocol.Rating;
using Hiperscan.ApoIdentCore.Reporting.Protocol.Result;
using Hiperscan.ApoIdentCore.Reporting.Protocol.Signature;
using Hiperscan.ApoIdentCore.Reporting.Protocol.SubstanceProperties;
using Hiperscan.ApoIdentCore.Reporting.Protocol.TestCertificate;
using Hiperscan.ApoIdentCommon.ApoConfig.Enums;
using Hiperscan.ApoIdentCommon.ApoConfig.ThirdPartyDataExchange;

namespace Hiperscan.ApoIdentCore.Reporting.Protocol
{
    public partial class GenericProtocol
    {
        protected List<IDraw> GetPageOneDrawings()
        {
            List<IDraw> drawings = new List<IDraw>();

            IDraw drawer = this.GetHeader();
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetAddress();
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetSubstanceProperties();
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetMethod();
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetComment();
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetGraphics();
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetResult();
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetRating();
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetClassificationAdvice();
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetAdditionalTest();
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetFinalResult(1);
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetTestCertificate(1);
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetCertifcationControl(1);
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetCannabisAdvice(1);
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetSignature(1);
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetFooter();
            if (drawer != null)
                drawings.Add(drawer);

            return drawings;
        }

        protected List<IDraw> GetPageTwoDrawings()
        {
            List<IDraw> drawings = new List<IDraw>();

            IDraw drawer = this.GetHeader();
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetAddress();
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetSubstanceProperties();
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetAdditionalTest();
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetFinalResult(2);
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetTestCertificate(2);
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetCertifcationControl(2);
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetCannabisAdvice(2);
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetSignature(2);
            if (drawer != null)
                drawings.Add(drawer);

            drawer = this.GetFooter();
            if (drawer != null)
                drawings.Add(drawer);

            return drawings;
        }

        protected IDraw GetHeader()
        {
            IDraw header = null;

            if (this.Args.Info.ProtocolType != ProtocolType.ApoIdent)
            {
                header = new CommonThirdPartyHeader();
            }
            else
            {
                if (this.Args.Info.AnalysisType == AnalysisType.Quantification)
                {
                    header = new CommonCannabisHeader();
                }
                else
                {
                    switch (this.Args.Info.ReportCountry)
                    {
                        case ReportCountryTypes.Austria:
                            header = new DeAUTHeader();
                            break;

                        case ReportCountryTypes.Germany:
                            header = new DeDEHeader();
                            break;

                        case ReportCountryTypes.Switzerland:
                            header = new DeCHHeader();
                            break;

                        case ReportCountryTypes.Brazil:
                            header = new PtBRHeader();
                            break;

                        default:
                            header = new EnGBHeader();
                            break;
                    }
                }
            }

            return header;
        }

        private IDraw GetAddress()
        {
            return new CommonAddress();
        }

        private IDraw GetSubstanceProperties()
        {
            IDraw drawer = null;

            if (this.Args.Info.AnalysisType == AnalysisType.Quantification)
            {
                drawer = new CommonCannabisSubstanceProperties();
            }
            else 
            {
                if (this.Args.Info.ReportCountry == ReportCountryTypes.Germany)
                    drawer = new DeDESubstanceProperties();
                else
                    drawer = new CommonSubstanceProperties();
            }

            return drawer;
        }

        private IDraw GetMethod()
        {
            IDraw drawer = null;

            if (this.Args.Info.AnalysisType == AnalysisType.Quantification)
            {
                drawer = new CommonCannabisMethod();
            }
            else
            {
                if (this.Args.Info.IsMeasurable)
                    drawer = new CommonMethod();
            }

            return drawer;
        }

        private IDraw GetComment()
        {
            return new CommonComment();
        }

        private IDraw GetGraphics()
        {
            IDraw drawer = null;

            if (this.Args.Info.IsMeasurable == false)
            {
                drawer = new CommonNotMeasurableGraphics();
            }
            else
            {
                if (this.Args.Info.AnalysisType == AnalysisType.Identification)
                    drawer = new CommonGraphics();
                else
                    drawer = new CommonCannabisGraphics();
            }

            return drawer;
        }

        private IDraw GetResult()
        {
            if (this.Args.Info.IsMeasurable == false)
                return null;

            IDraw drawer = null;

            if (this.Args.Info.AnalysisType == AnalysisType.Quantification)
            {
                if (Args.Info.CannabisResultIsTrustable == false)
                    drawer = new CommonNegativeCannabisResult();
                else
                    drawer = new CommonPositiveCannabisResult();
            }
            else
            {
                if (Args.Info.IsMatch)
                {
                    if (this.Args.Info.ClassificationType == AnalysisModule.Identification.ClassificationType.Single)
                        drawer = new CommonPositiveSingleResult();
                    else
                        drawer = new CommonPositiveClassificationResult();
                }
                else
                {
                    drawer = new CommonNegativeResult();
                }
            }

            return drawer;
        }

        private IDraw GetRating()
        {
            if (this.Args.Info.IsMeasurable == false)
                return null;

            IDraw drawer = null;

            if (this.Args.Info.AnalysisType == AnalysisType.Quantification)
            {
                if (this.Args.Info.CannabisResultIsTrustable)
                    drawer = new CommonCannabisRating();
            }
            else
            {
                drawer = new CommonRating();
            }


            return drawer;
        }

        private IDraw GetClassificationAdvice()
        {
            if (this.Args.Info.AnalysisType == AnalysisType.Quantification)
                return null;

            if (this.Args.Info.IsMeasurable == false)
                return null;

            if (this.Args.Info.ClassificationType != AnalysisModule.Identification.ClassificationType.Multiple)
                return null;

            return new CommonClassificationAdvice();

        }

        private IDraw GetAdditionalTest()
        {
            return new CommonAdditionalTest();
        }

        private IDraw GetFinalResult(int page)
        {
            if (this.Args.State.CurrentPage != page)
                return null;

            if (this.Args.Info.AnalysisType == AnalysisType.Quantification)
                return null;

            if (this.Args.State.CurrentPage == 1 && this.Args.State.IsSet(PdfCreationStates.CreateTwoPages) == true)
                return null;

            if (this.Args.Info.ClassificationType != ClassificationType.Multiple &&
                this.Args.Info.IsMeasurable == true &&
                this.Args.Info.IsMatch == true)
                return null;

            return new CommonFinalResult();
        }

        private IDraw GetTestCertificate(int page)
        {
            if (this.Args.State.CurrentPage != page)
                return null;

            if (this.Args.State.CurrentPage == 1 && this.Args.State.IsSet(PdfCreationStates.CreateTwoPages) == true)
                return null;

            return new CommonTestCertificate();
        }

        private IDraw GetCertifcationControl(int page)
        {
            if (this.Args.State.CurrentPage != page)
                return null;

            if (this.Args.State.CurrentPage == 1 && this.Args.State.IsSet(PdfCreationStates.CreateTwoPages) == true)
                return null;

            if (this.Args.Info.ReportCountry != ReportCountryTypes.Germany)
                return null;

            if (this.Args.Info.ProtocolType != ProtocolType.ApoIdent)
                return null;

            if (this.Args.Info.CertificationControl == false)
                return null;

            return new DeDECertificationControl();
        }

        private IDraw GetCannabisAdvice(int page)
        {
            if (this.Args.State.CurrentPage != page)
                return null;

            if (this.Args.State.CurrentPage == 1 && this.Args.State.IsSet(PdfCreationStates.CreateTwoPages) == true)
                return null;

            if (this.Args.Info.AnalysisType != AnalysisType.Quantification)
                return null;

            return new CommonCannabisAdvice();
        }

        private IDraw GetSignature(int page)
        {
            if (this.Args.State.CurrentPage != page)
                return null;

            if (this.Args.State.CurrentPage == 1 && this.Args.State.IsSet(PdfCreationStates.CreateTwoPages) == true)
                return null;

            return new CommonSignature();
        }


        private IDraw GetFooter()
        {
            return new CommonFooter();
        }
    }
}
