// Copyright 2020 De Staat der Nederlanden, Ministerie van Volksgezondheid, Welzijn en Sport.
// Licensed under the EUROPEAN UNION PUBLIC LICENCE v. 1.2
// SPDX-License-Identifier: EUPL-1.2

using System;
using NL.Rijksoverheid.ExposureNotification.BackEnd.Domain;
using NL.Rijksoverheid.ExposureNotification.BackEnd.Domain.DsosEncoding;

namespace NL.Rijksoverheid.ExposureNotification.BackEnd.DiagnosisKeys.Processors
{
    /// <summary>
    /// All assumed to be symptomatic before 2020/12/01
    /// Dependent on the NL TRL calculation.
    /// </summary>
    public class NlToEfgsDsosDiagnosticKeyProcessorMk1 : IDiagnosticKeyProcessor
    {
        public DkProcessingItem Execute(DkProcessingItem value)
        {
            if (!value.DiagnosisKey.Local.TransmissionRiskLevel.HasValue || !value.DiagnosisKey.Local.DaysSinceSymptomsOnset.HasValue)
            {
                throw new InvalidOperationException($"{nameof(NlToEfgsDsosDiagnosticKeyProcessorMk1)} requires TRL and DaysSinceSymptomsOnset.");
            }

            var baseValue = new DosViaTrlDayRangeMidPointCalculation().Calculate(value.DiagnosisKey.Local.DaysSinceSymptomsOnset.Value);
            value.DiagnosisKey.Efgs.DaysSinceSymptomsOnset = new DsosEncodingService().EncodeSymptomaticOnsetDateUnknown(baseValue);
            return value;
        }
    }
}
