using System.Text.Json.Serialization; namespace NetworkTool.Client.Models; public sealed class RemoteInterfaceAddressConfig { [JsonPropertyName("ip")] public string IP { get; init; } = string.Empty; [JsonPropertyName("prefix")] public int Prefix { get; init; } } public sealed class RemoteInterfaceRouteConfig { [JsonPropertyName("to")] public string To { get; init; } = string.Empty; [JsonPropertyName("via")] public string Via { get; init; } = string.Empty; } public sealed class RemoteInterfaceConfig { [JsonPropertyName("interface")] public string Interface { get; init; } = string.Empty; [JsonPropertyName("dhcp4")] public bool Dhcp4 { get; init; } [JsonPropertyName("addresses")] public IReadOnlyList Addresses { get; init; } = []; [JsonPropertyName("routes")] public IReadOnlyList Routes { get; init; } = []; [JsonPropertyName("dns")] public IReadOnlyList Dns { get; init; } = []; [JsonPropertyName("ip")] public string IP { get; init; } = string.Empty; [JsonPropertyName("prefix")] public int Prefix { get; init; } [JsonPropertyName("gateway")] public string Gateway { get; init; } = string.Empty; [JsonIgnore] public string DnsSummary => Dns is null || Dns.Count == 0 ? "无" : string.Join(Environment.NewLine, Dns); [JsonIgnore] public IReadOnlyList EffectiveAddresses => Addresses.Count > 0 ? Addresses : string.IsNullOrWhiteSpace(IP) ? [] : [new RemoteInterfaceAddressConfig { IP = IP, Prefix = Prefix }]; [JsonIgnore] public IReadOnlyList EffectiveRoutes => Routes.Count > 0 ? Routes : string.IsNullOrWhiteSpace(Gateway) ? [] : [new RemoteInterfaceRouteConfig { To = "default", Via = Gateway }]; } public sealed class RemoteInterfaceConfigsRequest { [JsonPropertyName("configs")] public IReadOnlyList Configs { get; init; } = []; } public sealed class RemoteInterfaceConfigsResponse { [JsonPropertyName("configs")] public IReadOnlyList Configs { get; init; } = []; [JsonPropertyName("errors")] public IReadOnlyList Errors { get; init; } = []; } public sealed class RemoteInterfaceConfigError { [JsonPropertyName("interface")] public string Interface { get; init; } = string.Empty; [JsonPropertyName("message")] public string Message { get; init; } = string.Empty; }