/*
 * Magic Cloud, copyright (c) 2023 Thomas Hansen. See the attached LICENSE file for details. For license inquiries you can send an email to thomas@ainiro.io
 */

using magic.node;
using magic.signals.contracts;
using magic.lambda.json.utilities;

namespace magic.lambda.json.slots.lambda
{
    /// <summary>
    /// [.to-json-raw] slot for transforming to a raw Newtonsoft JSON JContainer object, without
    /// ever transforming to a string.
    /// </summary>
    [Slot(
        Name = ".lambda2json-raw",
        Description = "Transforms a lambda hierarchy into a raw JSON container without serializing it to a string",
        ReturnsMode = SlotReturnsMode.Value,
        ReturnsKind = "json,text",
        ReturnsDescription = "Resolves to the generated raw JSON container",
        SignatureType = typeof(global::magic.lambda.json.signatures.Lambda2JsonRawSignature))]
    public class Lambda2JsonRaw : ISlot
    {
        /// <summary>
        /// Slot implementation.
        /// </summary>
        /// <param name="signaler">Signaler that raised signal.</param>
        /// <param name="input">Arguments to slot.</param>
        public void Signal(ISignaler signaler, Node input)
        {
            input.Value = Lambda2JsonTransformer.ToJson(input);
            input.Clear();
        }
    }
}
