using System;
using System.Collections.Generic;
using System.Linq;
using Ringtoets.AssemblyTool.Data;
using Ringtoets.Common.Data.Exceptions;
using Ringtoets.Integration.IO.Assembly;
using Ringtoets.WaveImpactAsphaltCover.Data;
namespace Ringtoets.Integration.IO.Factories
{
///
/// Factory to create instances of
/// with assembly results for wave impact asphalt cover.
///
public static class ExportableWaveImpactAsphaltCoverFailureMechanismFactory
{
private const ExportableFailureMechanismType failureMechanismCode = ExportableFailureMechanismType.AGK;
private const ExportableFailureMechanismGroup failureMechanismGroup = ExportableFailureMechanismGroup.Group3;
private const ExportableAssemblyMethod failureMechanismAssemblyMethod = ExportableAssemblyMethod.WBI1A1;
///
/// Creates a
/// with assembly results based on the input parameters.
///
/// The to create a
/// for.
/// A with assembly results.
/// Thrown when any parameter is null.
/// Thrown when assembly results cannot be created.
public static ExportableFailureMechanism CreateExportableWaveImpactAsphaltCoverFailureMechanism(
WaveImpactAsphaltCoverFailureMechanism failureMechanism)
{
if (failureMechanism == null)
{
throw new ArgumentNullException(nameof(failureMechanism));
}
if (!failureMechanism.IsRelevant)
{
return ExportableFailureMechanismFactory.CreateDefaultExportableFailureMechanismWithoutProbability(failureMechanismCode,
failureMechanismGroup,
failureMechanismAssemblyMethod);
}
FailureMechanismAssemblyCategoryGroup failureMechanismAssembly = WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism);
Dictionary failureMechanismSectionsLookup =
failureMechanism.SectionResults
.ToDictionary(sectionResult => sectionResult,
sectionResult => ExportableFailureMechanismSectionFactory.CreateExportableFailureMechanismSection(sectionResult.Section));
return new ExportableFailureMechanism(
new ExportableFailureMechanismAssemblyResult(failureMechanismAssemblyMethod,
failureMechanismAssembly),
failureMechanismSectionsLookup.Values, CreateFailureMechanismSectionResults(failureMechanismSectionsLookup),
failureMechanismCode,
failureMechanismGroup);
}
///
/// Creates a collection of
/// with assembly results based on the sections in .
///
/// The mapping between the
/// and .
/// A collection of .
/// Thrown when assembly results cannot be created.
private static IEnumerable CreateFailureMechanismSectionResults(
Dictionary failureMechanismSections)
{
var exportableResults = new List();
foreach (KeyValuePair failureMechanismSectionPair in failureMechanismSections)
{
WaveImpactAsphaltCoverFailureMechanismSectionResult failureMechanismSectionResult = failureMechanismSectionPair.Key;
FailureMechanismSectionAssemblyCategoryGroup simpleAssembly =
WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.AssembleSimpleAssessment(failureMechanismSectionResult);
FailureMechanismSectionAssemblyCategoryGroup detailedAssembly =
WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.AssembleDetailedAssessment(failureMechanismSectionResult);
FailureMechanismSectionAssemblyCategoryGroup tailorMadeAssembly =
WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment(failureMechanismSectionResult);
FailureMechanismSectionAssemblyCategoryGroup combinedAssembly =
WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.AssembleCombinedAssessment(failureMechanismSectionResult);
exportableResults.Add(
new ExportableAggregatedFailureMechanismSectionAssemblyResult(
failureMechanismSectionPair.Value,
ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResult(simpleAssembly, ExportableAssemblyMethod.WBI0E1),
ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResult(detailedAssembly, ExportableAssemblyMethod.WBI0G6),
ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResult(tailorMadeAssembly, ExportableAssemblyMethod.WBI0T4),
ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResult(combinedAssembly, ExportableAssemblyMethod.WBI0A1)));
}
return exportableResults;
}
}
}