/*
 * 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 System;
using magic.node;
using magic.node.extensions;
using magic.signals.contracts;

namespace magic.lambda.math.scalars
{
    /// <summary>
    /// [math.round] slot for rounding numbers.
    /// </summary>
    [Slot(
        Name = "math.round",
        Description = "Rounds a number",
        ValueKind = "number",
        ValueDescription = "Numeric value to round",
        ValueRequired = true,
        ValueMode = SlotValueMode.ValueOrExpression,
        ReturnsMode = SlotReturnsMode.Value,
        ReturnsKind = "number",
        ReturnsDescription = "Resolves to the rounded value")]
    public class Round : ISlot
    {
        /// <summary>
        /// Implementation of slot.
        /// </summary>
        /// <param name="signaler">Signaler used to raise the signal.</param>
        /// <param name="input">Arguments to slot.</param>
        /// <returns>An awaitable task.</returns>
        public void Signal(ISignaler signaler, Node input)
        {
            dynamic original = input.GetEx<dynamic>();
            input.Value = Math.Round(original);
        }
    }
}
