using Opc.Ua;
using Opc.Ua.Client;


namespace console_opcua_sgdn_tornio.Controllers
{
    static class HeidenhainNodes
    {
        // Stato programma
        public static readonly NodeId ProgramRunning =
            new("ns=1;s=Channel1.State.ProgramRunning");

        public static readonly NodeId ProgramName =
            new("ns=1;s=Channel1.Program.Name");

        // Mandrino
        public static readonly NodeId SpindleOn =
            new("ns=1;s=Channel1.Spindle.Running");

        // Errori
        public static readonly NodeId NcError =
            new("ns=1;s=Channel1.Error.Active");

        // Q-Parameter OP ID
        public static readonly NodeId Q100 =
            new("ns=1;s=Channel1.QParameters[100]");
    }
    public class OpcUaReader
    {
        private readonly Session _session;

        public OpcUaReader(Session session)
        {
            _session = session;
        }

        public async Task<bool> ReadBool(NodeId nodeId)
        {
            var value = await _session.ReadValueAsync<bool>(nodeId);
            return value;
        }

        public async Task<int> ReadInt(NodeId nodeId)
        {
            var value = await _session.ReadValueAsync<int>(nodeId);
            return value;
        }

        public string ReadString(NodeId nodeId)
        {
            var value = _session.ReadValue(nodeId);
            return value.Value?.ToString();
        }
    }
}
