// Created with MonoDevelop
//
//    QuickStep: Acquire, view and identify spectra 
//    Copyright (C) 2022, 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.Common.IO;
using System.Globalization;
using Hiperscan.AnalysisModule.Identification;
using Hiperscan.AnalysisModule;
using Hiperscan.ApoIdentCommon.ApoConfig.Enums;

namespace Hiperscan.ApoIdentCore.Reporting.ReportData
{
    public partial class ReportInfo
    {
        public const double NO_QUANTIFIER_RESULT = -100;

        public DateTime MinExpiryDate
        {
            get
            {
                if (String.IsNullOrEmpty(this.GracePeriodValue))
                    return this.ExpireDate;

                DateTime grace_period_date = this.Date;

                if (Int32.TryParse(this.GracePeriodValue, NumberStyles.None, CultureInfo.CurrentCulture, out int result))
                {
                    switch (this.GracePeriodUnit)
                    {
                        case GracePeriodTypes.Days:
                            grace_period_date = grace_period_date.AddDays(result);
                            break;

                        case GracePeriodTypes.Weeks:
                            grace_period_date = grace_period_date.AddDays(result * 7);
                            break;

                        case GracePeriodTypes.Months:
                            grace_period_date = grace_period_date.AddMonths(result);
                            break;

                        case GracePeriodTypes.Years:
                            grace_period_date = grace_period_date.AddYears(result);
                            break;

                        default:
                            grace_period_date = DateTime.MaxValue;
                            break;
                    }
                }

                if (this.ExpireDate < grace_period_date)
                    return this.ExpireDate;

                return grace_period_date;
            }
        }

        public string ReferenceQuantity
        {
            get
            {
                if (this.ReferenceQuantityUnit == ReferenceQuantityTypes.None)
                    return String.Empty;

                if (String.IsNullOrEmpty(this.ReferenceQuantityValue))
                    return String.Empty;

                return String.Format("{0} {1}", this.ReferenceQuantityValue,
                                     this.ReferenceQuantityUnit.xGetI18nString());
            }
        }

        public string GracePeriod
        {
            get 
            {
                if (this.GracePeriodUnit == GracePeriodTypes.None)
                    return String.Empty;

                if (String.IsNullOrEmpty(this.GracePeriodValue))
                    return String.Empty;

                return String.Format("{0} {1}", this.GracePeriodValue,
                                     this.GracePeriodUnit.xGetI18nString());
            }
        }

        public string Price
        {
            get
            {
                if (String.IsNullOrEmpty(this.PriceUnit))
                    return String.Empty;

                if (String.IsNullOrEmpty(this.PriceValue))
                    return String.Empty;

                return String.Format("{0} {1}", this.PriceValue,
                                     this.PriceUnit);
            }
        }

        public string ProduceAndDistributor
        {
            get
            {
                string producer_distributor = this.Producer;

                if (String.IsNullOrEmpty(producer_distributor))
                {
                    producer_distributor = this.Distributor;
                }
                else
                {
                    if (String.IsNullOrEmpty(this.Distributor) == false)
                        producer_distributor += " / " + this.Distributor;
                }

                return producer_distributor;
            }
        }

        [XmlSerialization]
        public string Company { get; set; } = String.Empty;

        [XmlSerialization] 
        public string Street { get; set; } = String.Empty;

        [XmlSerialization] 
        public string Town { get; set; } = String.Empty;


        [XmlSerialization] 
        public string Ppn { get; set; } = String.Empty;

        [XmlSerialization("Manufacturer")]
        public string Producer { get; set; } = String.Empty;

        [XmlSerialization]
        public string Batch { get; set; } = String.Empty;

        [XmlSerialization]
        public string ReferenceQuantityValue { get; set; } = String.Empty;

        [XmlSerialization]
        public ReferenceQuantityTypes ReferenceQuantityUnit { get; set; } = ReferenceQuantityTypes.None;

        [XmlSerialization]
        public string Distributor { get; set; } = String.Empty;

        [XmlSerialization]
        public string PriceValue { get; set; } = String.Empty;

        [XmlSerialization]
        public string PriceUnit { get; set; } = String.Empty;

        [XmlSerialization]
        public DateTime ExpireDate { get; set; } = DateTime.Now;

        [XmlSerialization]
        public string GracePeriodValue { get; set; } = String.Empty;

        [XmlSerialization]
        public GracePeriodTypes GracePeriodUnit { get; set; } = GracePeriodTypes.None;

        [XmlSerialization] 
        public string CorrectionFactor { get; set; } = String.Empty;

        [XmlSerialization]
        public DateTime DeliveryDate { get; set; } = DateTime.Now;



        [XmlSerialization] 
        public DateTime Date { get; set; } = DateTime.Now;

        [XmlSerialization("BAKMrkingActivated")] 
        public bool BAKMarkingActivated { get; set; } = true;

        [XmlSerialization] 
        public BAKMarkingState BAKMarking { get; set; } = BAKMarkingState.None;

        [XmlSerialization] 
        public string SubstanceClass { get; set; } = String.Empty;

        [XmlSerialization] 
        public string DefaultName { get; set; } = String.Empty;

        [XmlSerialization] 
        public string LatinName { get; set; } = String.Empty;

        [XmlSerialization] 
        public string SelectedName { get; set; } = String.Empty;

        [XmlSerialization] 
        public string SubstanceTradeName { get; set; } = String.Empty;

        [XmlSerialization] 
        public string TestId { get; set; } = String.Empty;

        [XmlSerialization("User")] 
        public string Operator { get; set; } = String.Empty;

        [XmlSerialization] 
        public string Comment { get; set; } = String.Empty;

        [XmlSerialization] 
        public bool HasCustomerResult { get; set; } = false;

        [XmlSerialization] 
        public bool CustomerResult { get; set; } = false;

        [XmlSerialization] 
        public bool IsMatch { get; set; } = false;

        [XmlSerialization] 
        public ClassificationType ClassificationType { get; set; }

        [XmlSerialization] 
        public bool IsMeasurable { get; set; } = true;

        [XmlSerialization]
        public ReportCountryTypes ReportCountry { get; set; } = ReportCountryTypes.Germany;

        [XmlSerialization]
        public string THCInput { get; set; } = String.Empty;

        [XmlSerialization]
        public string CBDInput { get; set; } = String.Empty;

        [XmlSerialization]
        public double RawTHCResult { get; set; } = ReportInfo.NO_QUANTIFIER_RESULT;

        [XmlSerialization]
        public double RawCBDResult { get; set; } = ReportInfo.NO_QUANTIFIER_RESULT;

        [XmlSerialization]
        public string Variety { get; set; } = String.Empty;

        [XmlSerialization]
        public AnalysisType AnalysisType { get; set; } = AnalysisType.Identification;

        [XmlSerialization]
        public string CannabisClassification { get; set; } = String.Empty;

        [XmlSerialization]
        public bool CannabisResultIsTrustable { get; set; } = false;
    }
}
