namespace MinicsConsole.Helper.RawDataFilter;
public class Mini8DataRecorderLayer(byte mini8Index, ILog log, Mini8DataDispatcher dataDispatcher) : IMini8DataFilter
{
    public IDataSender? NextSender { get; set; }
    public ChannelDataBaseHelper? DataBaseHelper { get; set; }

    public bool Send(Mini8Output mini8Output, ChannelData channelData, object? state)
    {
        switch (mini8Output.AutoTuneStatus)
        {
            case AutoTuneStatus.Unavailable:
            case AutoTuneStatus.Ready:
            case AutoTuneStatus.Triggered:
            case AutoTuneStatus.Tuning:
            case AutoTuneStatus.Complete:
            case AutoTuneStatus.Aborted:
            case AutoTuneStatus.Timeout:
            case AutoTuneStatus.Overflow:
                break;
            default:
                //log.Warning($"Mini8 - {mini8Index} - Channel {channel} Dirty Data PV: {mini8Output.PV} ℃");
                return true;
        }

        mini8Output.Adapt(channelData);
        dataDispatcher?.ChannelInfoNotify(mini8Index, mini8Output.ChannelIndex, channelData);

        switch (mini8Output.Inhibit)
        {
            case Inhibit.Enable:
                break;
            case Inhibit.Disable:
                return true;
            default:
                log.Warning($"Mini8 - {mini8Index} - Channel {mini8Output.ChannelIndex} Unknow Inhibit: {(byte)mini8Output.Inhibit}");
                return true;
        }
        DataBaseHelper?.InsertDB_ChannelData(channelData, mini8Output);
        return this.NextSender?.Send(mini8Output, channelData, null) is true;
    }
}