using ZB.MOM.WW.OtOpcUa.Configuration.Validation;

namespace ZB.MOM.WW.OtOpcUa.Configuration.Apply;

/// <summary>
///     Applies a <see cref="GenerationDiff"/> to whatever backing runtime the node owns: the OPC UA
///     address space, driver subscriptions, the local cache, etc. The Core project wires concrete
///     callbacks into this via <see cref="ApplyCallbacks"/> so the Configuration project stays free
///     of a Core/Server dependency (interface independence per decision #59).
/// </summary>
public interface IGenerationApplier
{
    Task<ApplyResult> ApplyAsync(DraftSnapshot? from, DraftSnapshot to, CancellationToken ct);
}

public sealed record ApplyResult(
    bool Succeeded,
    GenerationDiff Diff,
    IReadOnlyList<string> Errors)
{
    public static ApplyResult Ok(GenerationDiff diff) => new(true, diff, []);
    public static ApplyResult Fail(GenerationDiff diff, IReadOnlyList<string> errors) => new(false, diff, errors);
}
