<commit_before>﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LicenseData.cs" company="Kephas Software SRL">
//   Copyright (c) Kephas Software SRL. All rights reserved.
//   Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>
// <summary>
//   Implements the license class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

#nullable enable

namespace Kephas.Licensing
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    using Kephas.Data;
    using Kephas.Diagnostics.Contracts;

    /// <summary>
    /// Class storing license data.
    /// </summary>
    public sealed class LicenseData : ICloneable, IIdentifiable
    {
        private const int ParseChecksumInvalidCode = 3;
        private const int ChecksumInvalidCode = 4;
        private const string DateTimeFormat = "yyyy-MM-dd";

        /// <summary>
        /// Initializes a new instance of the <see cref="LicenseData"/> class.
        /// </summary>
        /// <param name="id">The license identifier.</param>
        /// <param name="appId">The regular expression matching the identifier of the application.</param>
        /// <param name="appVersionRange">The application version range.</param>
        /// <param name="licenseType">The type of the license.</param>
        /// <param name="licensedTo">The entity the application is licensed to.</param>
        /// <param name="licensedBy">The entity that licensed the application.</param>
        /// <param name="validFrom">Optional. The date the license is valid from.</param>
        /// <param name="validTo">Optional. The date the license is valid to.</param>
        /// <param name="data">Optional. The additional data associated with the license.</param>
        public LicenseData(
            string id,
            string appId,
            string appVersionRange,
            string licenseType,
            string licensedTo,
            string licensedBy,
            DateTime? validFrom = null,
            DateTime? validTo = null,
            IDictionary<string, string?>? data = null)
        {
            Requires.NotNullOrEmpty(id, nameof(id));
            Requires.NotNullOrEmpty(appId, nameof(appId));
            Requires.NotNullOrEmpty(appVersionRange, nameof(appVersionRange));
            Requires.NotNullOrEmpty(licenseType, nameof(licenseType));
            Requires.NotNullOrEmpty(licensedTo, nameof(licensedTo));
            Requires.NotNullOrEmpty(licensedBy, nameof(licensedBy));

            this.Id = id;
            this.AppId = appId;
            this.AppVersionRange = appVersionRange;
            this.LicenseType = licenseType;
            this.LicensedTo = licensedTo;
            this.LicensedBy = licensedBy;
            this.ValidFrom = validFrom;
            this.ValidTo = validTo;
            this.Data = data ?? new Dictionary<string, string?>();
        }

        /// <summary>
        /// Gets the license identifier.
        /// </summary>
        /// <value>
        /// The license identifier.
        /// </value>
        public string Id { get; }

        /// <summary>
        /// Gets the identifier for this instance.
        /// </summary>
        /// <value>
        /// The identifier.
        /// </value>
        object IIdentifiable.Id => this.Id;

        /// <summary>
        /// Gets a regular expression matching the identifier of the application.
        /// </summary>
        /// <value>
        /// The regular expression matching identifier of the application.
        /// </value>
        public string AppId { get; }

        /// <summary>
        /// Gets the application version range.
        /// </summary>
        /// <value>
        /// The application version range.
        /// </value>
        public string AppVersionRange { get; }

        /// <summary>
        /// Gets the date from which the license is valid.
        /// </summary>
        /// <value>
        /// The valid from date.
        /// </value>
        public DateTime? ValidFrom { get; }

        /// <summary>
        /// Gets the date to which this license is valid.
        /// </summary>
        /// <value>
        /// The valid to date.
        /// </value>
        public DateTime? ValidTo { get; }

        /// <summary>
        /// Gets the entity that issued this license.
        /// </summary>
        /// <value>
        /// Describes who issued this object.
        /// </value>
        public string LicensedBy { get; }

        /// <summary>
        /// Gets the entity that licensed the application.
        /// </summary>
        /// <value>
        /// The entity that licensed the application.
        /// </value>
        public string LicensedTo { get; }

        /// <summary>
        /// Gets the type of the license.
        /// </summary>
        /// <value>
        /// The type of the license.
        /// </value>
        public string LicenseType { get; }

        /// <summary>
        /// Gets additional data associated with the license.
        /// </summary><commit_msg>Doc changes<commit_after>﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LicenseData.cs" company="Kephas Software SRL">
//   Copyright (c) Kephas Software SRL. All rights reserved.
//   Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>
// <summary>
//   Implements the license class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

#nullable enable

namespace Kephas.Licensing
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    using Kephas.Data;
    using Kephas.Diagnostics.Contracts;

    /// <summary>
    /// Class storing license data.
    /// </summary>
    public sealed class LicenseData : ICloneable, IIdentifiable
    {
        private const int ParseChecksumInvalidCode = 3;
        private const int ChecksumInvalidCode = 4;
        private const string DateTimeFormat = "yyyy-MM-dd";

        /// <summary>
        /// Initializes a new instance of the <see cref="LicenseData"/> class.
        /// </summary>
        /// <param name="id">The license identifier.</param>
        /// <param name="appId">The regular expression matching the identifier of the application.</param>
        /// <param name="appVersionRange">The application version range.</param>
        /// <param name="licenseType">The type of the license.</param>
        /// <param name="licensedTo">The entity the application is licensed to.</param>
        /// <param name="licensedBy">The entity that licensed the application.</param>
        /// <param name="validFrom">Optional. The date the license is valid from.</param>
        /// <param name="validTo">Optional. The date the license is valid to.</param>
        /// <param name="data">Optional. The additional data associated with the license.</param>
        public LicenseData(
            string id,
            string appId,
            string appVersionRange,
            string licenseType,
            string licensedTo,
            string licensedBy,
            DateTime? validFrom = null,
            DateTime? validTo = null,
            IDictionary<string, string?>? data = null)
        {
            Requires.NotNullOrEmpty(id, nameof(id));
            Requires.NotNullOrEmpty(appId, nameof(appId));
            Requires.NotNullOrEmpty(appVersionRange, nameof(appVersionRange));
            Requires.NotNullOrEmpty(licenseType, nameof(licenseType));
            Requires.NotNullOrEmpty(licensedTo, nameof(licensedTo));
            Requires.NotNullOrEmpty(licensedBy, nameof(licensedBy));

            this.Id = id;
            this.AppId = appId;
            this.AppVersionRange = appVersionRange;
            this.LicenseType = licenseType;
            this.LicensedTo = licensedTo;
            this.LicensedBy = licensedBy;
            this.ValidFrom = validFrom;
            this.ValidTo = validTo;
            this.Data = data ?? new Dictionary<string, string?>();
        }

        /// <summary>
        /// Gets the license identifier.
        /// </summary>
        /// <value>
        /// The license identifier.
        /// </value>
        public string Id { get; }

        /// <summary>
        /// Gets the identifier for this instance.
        /// </summary>
        /// <value>
        /// The identifier.
        /// </value>
        object IIdentifiable.Id => this.Id;

        /// <summary>
        /// Gets a regular expression matching the identifier of the application.
        /// </summary>
        /// <value>
        /// The regular expression matching identifier of the application.
        /// </value>
        public string AppId { get; }

        /// <summary>
        /// Gets the application version range.
        /// </summary>
        /// <value>
        /// The application version range.
        /// </value>
        public string AppVersionRange { get; }

        /// <summary>
        /// Gets the date from which the license is valid.
        /// </summary>
        /// <value>
        /// The valid from date.
        /// </value>
        public DateTime? ValidFrom { get; }

        /// <summary>
        /// Gets the date to which this license is valid.
        /// </summary>
        /// <value>
        /// The valid to date.
        /// </value>
        public DateTime? ValidTo { get; }

        /// <summary>
        /// Gets the entity that issued this license.
        /// </summary>
        /// <value>
        /// Describes who issued this object.
        /// </value>
        public string LicensedBy { get; }

        /// <summary>
        /// Gets the entity the license is assigned to.
        /// </summary>
        /// <value>
        /// The entity the license is assigned to.
        /// </value>
        public string LicensedTo { get; }

        /// <summary>
        /// Gets the type of the license.
        /// </summary>
        /// <value>
        /// The type of the license.
        /// </value>
        public string LicenseType { get; }

        /// <summary>
        /// Gets additional data associated with the license.
        /// </summary>
{'fraction_non_alphanumeric': 0.1650171298058622, 'fraction_numerical': 0.00038066235249333843, 'mean_word_length': 1.4973859315589353, 'pattern_counts': {'":': 0, '<': 137, '<?xml version=': 0, '>': 139, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '118965', 'n_tokens_mistral': 2535, 'n_tokens_neox': 2506, 'n_words': 796}