using IPA.Utilities;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace IPA.Config.Data
{
///
/// A map of to for serialization by an .
/// Use or to create.
///
public sealed class Map : Value, IDictionary
{
private readonly Dictionary values = new Dictionary();
internal Map() { }
///
/// Accesses the at in the map.
///
/// the key to get the value associated with
/// the value associated with the
///
public Value this[string key] { get => values[key]; set => values[key] = value; }
///
/// Gets a collection of the keys for the .
///
///
public ICollection Keys => values.Keys;
///
/// Gets a collection of the values in the .
///
///
public ICollection Values => values.Values;
///
/// Gets the number of key-value pairs in this .
///
///
public int Count => values.Count;
bool ICollection>.IsReadOnly => ((IDictionary)values).IsReadOnly;
///
/// Adds a new with a given key.
///
/// the key to put the value at
/// the to add
///
public void Add(string key, Value value) => values.Add(key, value);
void ICollection>.Add(KeyValuePair item)
=> ((IDictionary)values).Add(item);
///
/// Clears the of its key-value pairs.
///
///
public void Clear() => values.Clear();
bool ICollection>.Contains(KeyValuePair item)
=> ((IDictionary)values).Contains(item);
///
/// Checks if the contains a given .
///
/// the key to check for
/// if the key exists, otherwise
///
public bool ContainsKey(string key) => values.ContainsKey(key);
void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex)
=> ((IDictionary)values).CopyTo(array, arrayIndex);
///
/// Enumerates the 's key-value pairs.
///
/// an of key-value pairs in this
///
public IEnumerator> GetEnumerator() => values.GetEnumerator();
///
/// Removes the object associated with a key in this .
///
/// the key to remove
/// if the key existed, otherwise
///
public bool Remove(string key) => values.Remove(key);
bool ICollection>.Remove(KeyValuePair item)
=> ((IDictionary)values).Remove(item);
///
/// Gets the value associated with the specified key.
///
/// the key of the value to get
/// the target location of the retrieved object
/// if the key was found and set, otherwise
///
public bool TryGetValue(string key, out Value value) => values.TryGetValue(key, out value);
IEnumerator IEnumerable.GetEnumerator() => ((IDictionary)values).GetEnumerator();
///
/// Converts this into a human-readable format.
///
/// a JSON-like set of key-value pairs
public override string ToString()
=> $"{{{string.Join(",", this.Select(p => $"\"{p.Key}\":{p.Value.ToString()}").StrJP())}}}";
}
}