using System.Diagnostics.CodeAnalysis;
using System.Numerics;
namespace RhythmBase.Components.RichText
{
///
/// Defines the interface for rich string styles.
///
/// The type that implements this interface.
public interface IRDRichStringStyle : IEqualityOperators, IEquatable
where TSelf : IRDRichStringStyle
{
///
/// Determines whether the specified object is equal to the current object.
///
/// The object to compare with the current object.
/// True if the specified object is equal to the current object; otherwise, false.
bool Equals([NotNullWhen(true)] object? obj) => obj is TSelf e && Equals(e);
///
/// Gets the closing tag for the specified name.
///
/// The name of the tag.
/// The closing tag for the specified name.
static string GetCloseTag(string name) => $"{name}>";
///
/// Gets the opening tag for the specified name and optional argument.
///
/// The name of the tag.
/// The optional argument for the tag.
/// The opening tag for the specified name and optional argument.
static string GetOpenTag(string name, string? arg = null)=> arg is null ? $"<{name}>" : $"<{name}={arg}>";
///
/// Generates an XML tag representing the differences between two instances.
///
/// The initial instance.
/// The modified instance.
/// A string containing the XML tag that represents the differences between the two instances.
static abstract string GetXmlTag(TSelf before, TSelf after);
///
/// Resets the property of the rich string style based on the provided name.
///
/// The name of the property to reset.
/// True if the property was successfully reset; otherwise, false.
bool ResetProperty(string name);
///
/// Sets the property of the rich string style based on the provided name and value.
///
/// The name of the property to set.
/// The value to set for the property.
/// True if the property was successfully set; otherwise, false.
bool SetProperty(string name, string value);
///
/// Tries to add a tag to the specified string based on the provided name and boolean values.
///
/// The string to which the tag will be added.
/// The name of the tag.
/// A boolean value indicating whether the tag is before.
/// A boolean value indicating whether the tag is after.
static void TryAddTag(ref string tag, string name, bool before, bool after)
{
if (before != after)
tag += after
? GetOpenTag(name)
: GetCloseTag(name);
}
///
/// Tries to add a tag to the specified string based on the provided name and optional string values.
///
/// The string to which the tag will be added.
/// The name of the tag.
/// An optional string value indicating the tag before.
/// An optional string value indicating the tag after.
static void TryAddTag(ref string tag, string name, string? before, string? after)
{
if (before != after)
tag += after is null
? GetCloseTag(name)
: before is null
? GetOpenTag(name, after)
: GetCloseTag(name) + GetOpenTag(name, after);
}
///
/// Gets a value indicating whether the style has a phrase.
///
static abstract bool HasPhrase { get; }
}
}