namespace MiGu.Server.Configs;

public record DeviceDriverBinding(string Id, string DeviceType, string DriverName, string Version);

public record DeviceInstance(
    string Id, string Name, string DeviceType, string Protocol, string Address,
    string DriverId, bool Enabled);

public record DeviceHealthPolicy(int HeartbeatSec, int OfflineSec);

public record AlarmRule(string Level, string Condition);
public record AlarmPolicy(bool Enabled, List<AlarmRule> Rules);

public record DeviceManagementConfig(
    List<DeviceDriverBinding> Drivers,
    List<DeviceInstance> Devices,
    DeviceHealthPolicy HealthPolicy,
    AlarmPolicy AlarmPolicy)
{
    public static DeviceManagementConfig Default() => new(
        Drivers: new List<DeviceDriverBinding>
        {
            new("drv-elev", "电梯", "OpcUaElevatorDriver", "1.2.0"),
            new("drv-chrg", "充电桩", "ModbusChargerDriver", "1.0.5"),
            new("drv-cam", "摄像头", "OnvifCameraDriver", "2.1.0")
        },
        Devices: new List<DeviceInstance>
        {
            new("dev-elev-1", "#1 电梯", "电梯", "opc-ua", "opc.tcp://10.0.2.20:4840", "drv-elev", true),
            new("dev-chrg-1", "充电桩-A1", "充电桩", "modbus-tcp", "10.0.2.30:502", "drv-chrg", true)
        },
        HealthPolicy: new DeviceHealthPolicy(5, 30),
        AlarmPolicy: new AlarmPolicy(true, new List<AlarmRule>
        {
            new("warn", "offline>30s"),
            new("error", "driverException")
        }));
}
