// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. using System; using System.Collections.Generic; namespace PSTui.Models; /// /// Represents a value that can be displayed and compared in a data table. /// public interface IValue : IComparable { /// /// Gets or sets the string representation of the value for display purposes. /// string DisplayValue { get; set; } /// /// Gets the original object value before formatting. /// object? OriginalValue { get; } } /// /// Represents a decimal value in a data table with support for numeric sorting. /// public class DecimalValue : IValue { /// /// Gets or sets the string representation of the decimal value for display purposes. /// public required string DisplayValue { get; set; } /// /// Gets or sets the decimal value used for sorting. /// public decimal SortValue { get; set; } /// /// Gets the original decimal value. /// public object? OriginalValue => SortValue; /// /// Compares the current instance with another object of the same type. /// /// An object to compare with this instance. /// /// A value that indicates the relative order of the objects being compared. /// Less than zero if this instance precedes , /// zero if they are equal, or greater than zero if this instance follows . /// Returns 1 if is not a . /// public int CompareTo(object? obj) => obj is not DecimalValue otherDecimalValue ? 1 : decimal.Compare(SortValue, otherDecimalValue.SortValue); } /// /// Represents a string value in a data table with support for string sorting. /// public class StringValue : IValue { /// /// Gets or sets the string value for display and sorting purposes. /// public required string DisplayValue { get; set; } /// /// Gets or sets the original object value before conversion to string. /// public object? RawValue { get; set; } /// /// Gets the original object value. /// public object? OriginalValue => RawValue ?? DisplayValue; /// /// Compares the current instance with another object of the same type. /// /// An object to compare with this instance. /// /// A value that indicates the relative order of the objects being compared. /// Less than zero if this instance precedes , /// zero if they are equal, or greater than zero if this instance follows . /// Returns 1 if is not a . /// public int CompareTo(object? obj) => obj is not StringValue otherStringValue ? 1 : string.Compare(DisplayValue, otherStringValue.DisplayValue, StringComparison.Ordinal); } /// /// Represents a single row in a data table with values mapped to column identifiers. /// public class DataTableRow { /// /// Gets or sets the dictionary of values for this row, keyed by the column identifier. /// The key is the data column hash code serialized as a string for JSON compatibility. /// public Dictionary Values { get; set; } /// /// Gets or sets the original index of the object in the source collection before any transformations. /// public int OriginalObjectIndex { get; set; } /// /// Initializes a new instance of the class with the specified values and original index. /// /// The dictionary of values for this row, keyed by column identifier. /// The original index of the object in the source collection. public DataTableRow(Dictionary data, int originalObjectIndex) { Values = data; OriginalObjectIndex = originalObjectIndex; } }