#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IPA.Config.Data
{
///
/// A base value type for config data abstract representations, to be serialized with an
/// . If a is , then
/// that represents just that: a null in whatever serialization is being used.
/// Also contains factory functions for all derived types.
///
public abstract class Value
{
///
/// Converts this into a human-readable format.
///
/// a human-readable string containing the value provided
public abstract override string ToString();
///
/// Creates a Null .
///
///
public static Value? Null() => null;
///
/// Creates an empty .
///
/// an empty
///
public static List List() => new();
///
/// Creates an empty .
///
/// an empty
///
///
public static Map Map() => new();
///
/// Creates a new representing a .
///
/// the value to wrap
/// a wrapping
///
[return: NotNullIfNotNull("val")]
public static Text? From(string? val) => Text(val);
///
/// Creates a new object wrapping a .
///
/// the value to wrap
/// a wrapping
///
[return: NotNullIfNotNull("val")]
public static Text? Text(string? val) => val == null ? null : new(val);
///
/// Creates a new wrapping a .
///
/// the value to wrap
/// a wrapping
///
public static Integer From(long val) => Integer(val);
///
/// Creates a new wrapping a .
///
/// the value to wrap
/// a wrapping
///
public static Integer Integer(long val) => new(val);
///
/// Creates a new wrapping a .
///
/// the value to wrap
/// a wrapping
///
public static FloatingPoint From(decimal val) => Float(val);
///
/// Creates a new wrapping a .
///
/// the value to wrap
/// a wrapping
///
public static FloatingPoint Float(decimal val) => new(val);
///
/// Creates a new wrapping a .
///
/// the value to wrap
/// a wrapping
///
public static Boolean From(bool val) => Bool(val);
///
/// Creates a new wrapping a .
///
/// the value to wrap
/// a wrapping
///
public static Boolean Bool(bool val) => new(val);
///
/// Creates a new holding the content of an
/// of .
///
/// the s to initialize the with
/// a containing the content of
///
[return: NotNullIfNotNull("vals")]
public static List? From(IEnumerable? vals)
{
if (vals is null) return null;
var l = List();
l.AddRange(vals);
return l;
}
///
/// Creates a new holding the content of an
/// of to .
///
/// the dictionary of s to initialize the wtih
/// a containing the content of
///
///
public static Map From(IDictionary vals) => From(vals as IEnumerable>);
///
/// Creates a new holding the content of an
/// of of to .
///
/// the enumerable of of name to
/// a containing the content of
///
///
[return: NotNullIfNotNull("vals")]
public static Map? From(IEnumerable>? vals)
{
if (vals is null) return null;
var m = Map();
foreach (var v in vals) m.Add(v.Key, v.Value);
return m;
}
}
}