using ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.PlcFamilies;

namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy;

/// <summary>
///     AB Legacy (PCCC) driver configuration. One instance supports N devices (SLC 500 /
///     MicroLogix / PLC-5 / LogixPccc). Per plan decision #41 AbLegacy ships separately from
///     AbCip because PCCC's file-based addressing (<c>N7:0</c>) and Logix's symbolic addressing
///     (<c>Motor1.Speed</c>) pull the abstraction in different directions.
/// </summary>
public sealed class AbLegacyDriverOptions
{
    public IReadOnlyList<AbLegacyDeviceOptions> Devices { get; init; } = [];
    public IReadOnlyList<AbLegacyTagDefinition> Tags { get; init; } = [];
    public AbLegacyProbeOptions Probe { get; init; } = new();
    public TimeSpan Timeout { get; init; } = TimeSpan.FromSeconds(2);
}

public sealed record AbLegacyDeviceOptions(
    string HostAddress,
    AbLegacyPlcFamily PlcFamily = AbLegacyPlcFamily.Slc500,
    string? DeviceName = null);

/// <summary>
///     One PCCC-backed OPC UA variable. <paramref name="Address"/> is the canonical PCCC
///     file-address string that parses via <see cref="AbLegacyAddress.TryParse"/>.
/// </summary>
public sealed record AbLegacyTagDefinition(
    string Name,
    string DeviceHostAddress,
    string Address,
    AbLegacyDataType DataType,
    bool Writable = true,
    bool WriteIdempotent = false);

public sealed class AbLegacyProbeOptions
{
    public bool Enabled { get; init; } = true;
    public TimeSpan Interval { get; init; } = TimeSpan.FromSeconds(5);
    public TimeSpan Timeout { get; init; } = TimeSpan.FromSeconds(2);

    /// <summary>Probe address — defaults to <c>S:0</c> (status file, first word) when null.</summary>
    public string? ProbeAddress { get; init; } = "S:0";
}
