/*
 * 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.data.common.helpers;

namespace magic.lambda.mysql
{
    /// <summary>
    /// [mysql.transaction.commit] slot for committing the top level MySQL
    /// database transaction.
    /// </summary>
    [Slot(
        Name = "mysql.transaction.commit",
        Description = "Commits the current MySQL transaction",
        ReturnsMode = SlotReturnsMode.None,
        RequiresScope = "mysql.transaction",
        ScopeDescription = "Requires an active MySQL transaction created by [mysql.transaction.create]")]
    public class CommitTransaction : ISlot
    {
        /// <summary>
        /// Handles the signal for the class.
        /// </summary>
        /// <param name="signaler">Signaler used to signal the slot.</param>
        /// <param name="input">Root node for invocation.</param>
        public void Signal(ISignaler signaler, Node input)
        {
            signaler.Peek<Transaction>("mysql.transaction").Commit();
        }
    }
}
