<commit_before>﻿#region copyright

/* * * * * * * * * * * * * * * * * * * * * * * * * */
/* <NAME> IMT (IZfM Dresden)                   */
/* Softwaresystem PiWeb                            */
/* (c) <NAME> 2015                             */
/* * * * * * * * * * * * * * * * * * * * * * * * * */

#endregion

namespace Zeiss.PiWeb.Api.Rest.Dtos.Data
{
	#region usings

	using System;
	using System.Collections.Generic;
	using System.Globalization;
	using System.Linq;
	using System.Xml;
	using JetBrains.Annotations;
	using Newtonsoft.Json;

	#endregion

	/// <summary>
	/// Holds the configuration of the entire database and defines the possible attribute definitions of all entities.
	/// </summary>
	public class ConfigurationDto
	{
		#region members

		private IReadOnlyCollection<AbstractAttributeDefinitionDto> _PartAttributes = Array.Empty<AbstractAttributeDefinitionDto>();
		private IReadOnlyCollection<AbstractAttributeDefinitionDto> _CharacteristicAttributes = Array.Empty<AbstractAttributeDefinitionDto>();
		private IReadOnlyCollection<AbstractAttributeDefinitionDto> _MeasurementAttributes = Array.Empty<AbstractAttributeDefinitionDto>();
		private IReadOnlyCollection<AbstractAttributeDefinitionDto> _ValueAttributes = Array.Empty<AbstractAttributeDefinitionDto>();
		private IReadOnlyCollection<AttributeDefinitionDto> _CatalogAttributes = Array.Empty<AttributeDefinitionDto>();

		private Dictionary<ushort, AbstractAttributeDefinitionDto> _PartAttributesDict;
		private Dictionary<ushort, AbstractAttributeDefinitionDto> _CharacteristicAttributesDict;
		private Dictionary<ushort, AbstractAttributeDefinitionDto> _MeasurementAttributesDict;
		private Dictionary<ushort, AbstractAttributeDefinitionDto> _ValueAttributesDict;
		private Dictionary<ushort, AbstractAttributeDefinitionDto> _CatalogAttributesDict;
		private Dictionary<ushort, AbstractAttributeDefinitionDto> _AllAttributesDict;

		#endregion

		#region properties

		private Dictionary<ushort, AbstractAttributeDefinitionDto> PartAttributesDict
			=> _PartAttributesDict ??= FillTable( PartAttributes );

		private Dictionary<ushort, AbstractAttributeDefinitionDto> CharacteristicAttributesDict
			=> _CharacteristicAttributesDict ??= FillTable( CharacteristicAttributes );

		private Dictionary<ushort, AbstractAttributeDefinitionDto> MeasurementAttributesDict
			=> _MeasurementAttributesDict ??= FillTable( MeasurementAttributes );

		private Dictionary<ushort, AbstractAttributeDefinitionDto> ValueAttributesDict
			=> _ValueAttributesDict ??= FillTable( ValueAttributes );

		private Dictionary<ushort, AbstractAttributeDefinitionDto> CatalogAttributesDict
			=> _CatalogAttributesDict ??= FillTable( CatalogAttributes );

		private Dictionary<ushort, AbstractAttributeDefinitionDto> AllAttributesDict =>
			_AllAttributesDict ??= PartAttributesDict
				.Concat( CharacteristicAttributesDict )
				.Concat( MeasurementAttributesDict )
				.Concat( ValueAttributesDict )
				.Concat( CatalogAttributesDict )
				.ToDictionary( kvp => kvp.Key, kvp => kvp.Value );

		/// <summary>
		/// Returns a list of all attribute definitions in this configuration.
		/// </summary>
		[JsonIgnore]
		public IReadOnlyCollection<AbstractAttributeDefinitionDto> AllAttributes
		{
			[NotNull] get => AllAttributesDict.Values;
		}

		/// <summary>
		/// Gets or sets a list of all part attribute definitions.
		/// </summary>
		[JsonProperty( "partAttributes" )]
		public IReadOnlyCollection<AbstractAttributeDefinitionDto> PartAttributes
		{
			[NotNull] get => _PartAttributes;
			set
			{
				_PartAttributes = value ?? Array.Empty<AbstractAttributeDefinitionDto>();
				_PartAttributesDict = null;
			}
		}

		/// <summary>
		/// Gets or sets a list of all characteristic attribute definitions.
		/// </summary>
		[JsonProperty( "characteristicAttributes" )]
		public IReadOnlyCollection<AbstractAttributeDefinitionDto> CharacteristicAttributes
		{
			[NotNull] get => _CharacteristicAttributes;
			set
			{
				_CharacteristicAttributes = value ?? Array.Empty<AbstractAttributeDefinitionDto>();
				_CharacteristicAttributesDict = null;
			}
		}

		/// <summary>
		/// Gets or sets a list of all measurement attribute definitions.
		/// </summary>
		[JsonProperty( "measurementAttributes" )]
		public IReadOnlyCollection<AbstractAttributeDefinitionDto> MeasurementAttributes
		{
			[NotNull] get => _MeasurementAttributes;
			set
			{
				_MeasurementAttributes = value ?? Array.Empty<AbstractAttributeDefinitionDto>();
				_MeasurementAttributesDict = null;
			}
		}

		/// <summary>
		/// Gets or sets a list of all value attribute definitions.
		/// </summary>
		[JsonProperty( "valueAttributes" )]
		public IReadOnlyCollection<AbstractAttributeDefinitionDto> ValueAttributes
		{
			[NotNull] get => _ValueAttributes;
			set
			{
				_ValueAttributes = value ?? Array.Empty<AbstractAttributeDefinitionDto>();
				_ValueAttributesDict = null;
			}
		}

		/// <summary>
		/// Gets or sets a list of all catalog attribute definitions.
		/// </summary>
		[JsonProperty( "catalogAttributes" )]
		public IReadOnlyCollection<AttributeDefinitionDto> CatalogAttributes
		{
			[NotNull] get => _CatalogAttributes;
			set
			{
				_CatalogAttributes = value ?? Array.Empty<AttributeDefinitionDto>();
				_CatalogAttributesDict = null;
			}
		}

		/// <summary>
		/// The attribute <code>versioningType</code> defines, whether updates to parts or characteristics
		/// overwrite existing values, or whether they create a new version of the entity.
		/// </summary><commit_msg>refactor: Use IReadOnlyList instead of IReadOnlyCollection for convenience<commit_after>﻿#region copyright

/* * * * * * * * * * * * * * * * * * * * * * * * * */
/* <NAME> IMT (IZfM Dresden)                   */
/* Softwaresystem PiWeb                            */
/* (c) <NAME> 2015                             */
/* * * * * * * * * * * * * * * * * * * * * * * * * */

#endregion

namespace Zeiss.PiWeb.Api.Rest.Dtos.Data
{
	#region usings

	using System;
	using System.Collections.Generic;
	using System.Globalization;
	using System.Linq;
	using System.Xml;
	using JetBrains.Annotations;
	using Newtonsoft.Json;

	#endregion

	/// <summary>
	/// Holds the configuration of the entire database and defines the possible attribute definitions of all entities.
	/// </summary>
	public class ConfigurationDto
	{
		#region members

		private IReadOnlyList<AbstractAttributeDefinitionDto> _PartAttributes = Array.Empty<AbstractAttributeDefinitionDto>();
		private IReadOnlyList<AbstractAttributeDefinitionDto> _CharacteristicAttributes = Array.Empty<AbstractAttributeDefinitionDto>();
		private IReadOnlyList<AbstractAttributeDefinitionDto> _MeasurementAttributes = Array.Empty<AbstractAttributeDefinitionDto>();
		private IReadOnlyList<AbstractAttributeDefinitionDto> _ValueAttributes = Array.Empty<AbstractAttributeDefinitionDto>();
		private IReadOnlyList<AttributeDefinitionDto> _CatalogAttributes = Array.Empty<AttributeDefinitionDto>();

		private Dictionary<ushort, AbstractAttributeDefinitionDto> _PartAttributesDict;
		private Dictionary<ushort, AbstractAttributeDefinitionDto> _CharacteristicAttributesDict;
		private Dictionary<ushort, AbstractAttributeDefinitionDto> _MeasurementAttributesDict;
		private Dictionary<ushort, AbstractAttributeDefinitionDto> _ValueAttributesDict;
		private Dictionary<ushort, AbstractAttributeDefinitionDto> _CatalogAttributesDict;
		private Dictionary<ushort, AbstractAttributeDefinitionDto> _AllAttributesDict;

		#endregion

		#region properties

		private Dictionary<ushort, AbstractAttributeDefinitionDto> PartAttributesDict
			=> _PartAttributesDict ??= FillTable( PartAttributes );

		private Dictionary<ushort, AbstractAttributeDefinitionDto> CharacteristicAttributesDict
			=> _CharacteristicAttributesDict ??= FillTable( CharacteristicAttributes );

		private Dictionary<ushort, AbstractAttributeDefinitionDto> MeasurementAttributesDict
			=> _MeasurementAttributesDict ??= FillTable( MeasurementAttributes );

		private Dictionary<ushort, AbstractAttributeDefinitionDto> ValueAttributesDict
			=> _ValueAttributesDict ??= FillTable( ValueAttributes );

		private Dictionary<ushort, AbstractAttributeDefinitionDto> CatalogAttributesDict
			=> _CatalogAttributesDict ??= FillTable( CatalogAttributes );

		private Dictionary<ushort, AbstractAttributeDefinitionDto> AllAttributesDict =>
			_AllAttributesDict ??= PartAttributesDict
				.Concat( CharacteristicAttributesDict )
				.Concat( MeasurementAttributesDict )
				.Concat( ValueAttributesDict )
				.Concat( CatalogAttributesDict )
				.ToDictionary( kvp => kvp.Key, kvp => kvp.Value );

		/// <summary>
		/// Returns a list of all attribute definitions in this configuration.
		/// </summary>
		[JsonIgnore]
		public IReadOnlyCollection<AbstractAttributeDefinitionDto> AllAttributes
		{
			[NotNull] get => AllAttributesDict.Values;
		}

		/// <summary>
		/// Gets or sets a list of all part attribute definitions.
		/// </summary>
		[JsonProperty( "partAttributes" )]
		public IReadOnlyList<AbstractAttributeDefinitionDto> PartAttributes
		{
			[NotNull] get => _PartAttributes;
			set
			{
				_PartAttributes = value ?? Array.Empty<AbstractAttributeDefinitionDto>();
				_PartAttributesDict = null;
			}
		}

		/// <summary>
		/// Gets or sets a list of all characteristic attribute definitions.
		/// </summary>
		[JsonProperty( "characteristicAttributes" )]
		public IReadOnlyList<AbstractAttributeDefinitionDto> CharacteristicAttributes
		{
			[NotNull] get => _CharacteristicAttributes;
			set
			{
				_CharacteristicAttributes = value ?? Array.Empty<AbstractAttributeDefinitionDto>();
				_CharacteristicAttributesDict = null;
			}
		}

		/// <summary>
		/// Gets or sets a list of all measurement attribute definitions.
		/// </summary>
		[JsonProperty( "measurementAttributes" )]
		public IReadOnlyList<AbstractAttributeDefinitionDto> MeasurementAttributes
		{
			[NotNull] get => _MeasurementAttributes;
			set
			{
				_MeasurementAttributes = value ?? Array.Empty<AbstractAttributeDefinitionDto>();
				_MeasurementAttributesDict = null;
			}
		}

		/// <summary>
		/// Gets or sets a list of all value attribute definitions.
		/// </summary>
		[JsonProperty( "valueAttributes" )]
		public IReadOnlyList<AbstractAttributeDefinitionDto> ValueAttributes
		{
			[NotNull] get => _ValueAttributes;
			set
			{
				_ValueAttributes = value ?? Array.Empty<AbstractAttributeDefinitionDto>();
				_ValueAttributesDict = null;
			}
		}

		/// <summary>
		/// Gets or sets a list of all catalog attribute definitions.
		/// </summary>
		[JsonProperty( "catalogAttributes" )]
		public IReadOnlyList<AttributeDefinitionDto> CatalogAttributes
		{
			[NotNull] get => _CatalogAttributes;
			set
			{
				_CatalogAttributes = value ?? Array.Empty<AttributeDefinitionDto>();
				_CatalogAttributesDict = null;
			}
		}

		/// <summary>
		/// The attribute <code>versioningType</code> defines, whether updates to parts or characteristics
		/// overwrite existing values, or whether they create a new version of the entity.
		/// </summary>
{'fraction_non_alphanumeric': 0.0984568179767169, 'fraction_numerical': 0.0007219565021207473, 'mean_word_length': 4.491575817641229, 'pattern_counts': {'":': 0, '<': 109, '<?xml version=': 0, '>': 137, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3737019', 'n_tokens_mistral': 3177, 'n_tokens_neox': 2884, 'n_words': 664}