import 'package:uuid/uuid.dart';

///SP60设备管理器
abstract class IVBoxControlManager {
  /// 获取当前魔盒设备的UniqueId
  Future<String> getUltrasoundUniqueId();

  ///获取网卡信息
  Future<NetworkResult?> getNetworkCardsInfo();

  ///保存网卡信息
  Future<bool> saveNetworkCardsInfo(String networkWireListModel);

  ///获取无线网卡信息
  Future<NetworkWifiResult> getWirelessCardInfo();

  ///连接Wifi网络
  Future<bool> connectWifi(NetworkConnectWifi wifiInfo);

  ///断开Wifi网络
  Future<bool> disconnectWifi(NetworkConnectWifi wifiInfo);

  ///忘记Wifi密码
  Future<bool> forgetWifiPassword(NetworkConnectWifi wifiInfo);

  ///保存Wifi信息
  Future<bool> saveWifiNetworkCard(String wifiInfo);

  ///刷新DNS
  Future<bool> flushDNS();

  ///Ping 测试Ip是否可以连通
  Future<bool> ping(String ipInfo);

  ///绑定Sonopost唯一码
  Future<void> bindSonopostUniqueCode();

  ///是否显示硬件检测
  bool get canShowHardwareDetector;
  set canShowHardwareDetector(bool val);
}

///网卡信息结构
class NetworkResult {
  List<Interface> interfaces;

  NetworkResult({
    required this.interfaces,
  });

  factory NetworkResult.fromJson(Map<String, dynamic> json) {
    var list = json['Data']['Interfaces'] as List;
    List<Interface> interfaceList =
        list.map((i) => Interface.fromJson(i)).toList();

    return NetworkResult(
      interfaces: interfaceList,
    );
  }
  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['Interfaces'] = this.interfaces.map((e) => e.toJson()).toList();
    return data;
  }
}

///网卡信息子结构
class Interface {
  String guid;

  ///mac地址
  String macAddress;

  ///网卡名称
  String name;
  /////描述
  String description;

  ///是否开启DHCP
  bool enableDHCP;
  /////ip地址
  String ipAddress;

  ///子网掩码
  String subnetMask;

  ///默认网关
  String gateway;

  ///首选DNS
  String preferredDNS;

  ///备用DNS
  String standbyDNS;

  Interface({
    required this.guid,
    required this.macAddress,
    required this.name,
    required this.description,
    required this.enableDHCP,
    required this.ipAddress,
    required this.subnetMask,
    required this.gateway,
    required this.preferredDNS,
    required this.standbyDNS,
  });

  factory Interface.fromJson(Map<String, dynamic> json) {
    return Interface(
      guid: json['Guid'],
      macAddress: json['MacAddress'],
      name: json['Name'],
      description: json['Description'],
      enableDHCP: json['EnableDHCP'],
      ipAddress: json['IPAddress'],
      subnetMask: json['SubnetMask'],
      gateway: json['Gateway'],
      preferredDNS: json['PreferredDNS'],
      standbyDNS: json['StandbyDNS'],
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['Guid'] = this.guid;
    data['MacAddress'] = this.macAddress;
    data['Name'] = this.name;
    data['Description'] = this.description;
    data['EnableDHCP'] = this.enableDHCP;
    data['IPAddress'] = this.ipAddress;
    data['SubnetMask'] = this.subnetMask;
    data['Gateway'] = this.gateway;
    data['PreferredDNS'] = this.preferredDNS;
    data['StandbyDNS'] = this.standbyDNS;
    return data;
  }
}

///无线网卡信息结构
class NetworkWifiResult {
  final bool isSuccess;
  final Data? data;

  NetworkWifiResult({required this.isSuccess, this.data});

  factory NetworkWifiResult.fromJson(Map<String, dynamic> json) {
    var dataJson = json['Data'] as Map<String, dynamic>;
    Data data = Data.fromJson(dataJson);
    return NetworkWifiResult(
      isSuccess: json['IsSuccess'],
      data: data,
    );
  }
}

///无线网卡信息子结构1
class Point {
  final String id;
  String? name;
  final String? signalStrength;
  bool? hasProfile;
  final bool? isSecure;
  bool? isConnected;
  String? password;

  Point({
    String? id,
    this.name,
    this.signalStrength,
    this.hasProfile,
    this.isSecure,
    this.isConnected,
    this.password,
  }) : id = id ?? Uuid().v4();

  factory Point.fromJson(Map<String, dynamic> json) {
    return Point(
      id: json['Id'] ?? Uuid().v4(),
      name: json['Name'],
      signalStrength: json['SignalStrength'],
      hasProfile: json['HasProfile'],
      isSecure: json['IsSecure'],
      isConnected: json['IsConnected'],
      password: json['Password'],
    );
  }
}

///无线网卡信息子结构2
class Data {
  final String guid;
  final String macAddress;
  final String name;
  final String description;
  final bool enableDHCP;
  final String ipAddress;
  final String subnetMask;
  final String gateway;
  final String preferredDNS;
  final String standbyDNS;
  final List<Point> points;

  Data({
    required this.guid,
    required this.macAddress,
    required this.name,
    required this.description,
    required this.enableDHCP,
    required this.ipAddress,
    required this.subnetMask,
    required this.gateway,
    required this.preferredDNS,
    required this.standbyDNS,
    required this.points,
  });

  factory Data.fromJson(Map<String, dynamic> json) {
    var list = json['Points'] as List;
    List<Point> pointList = list.map((i) => Point.fromJson(i)).toList();
    return Data(
      guid: json['Guid'],
      macAddress: json['MacAddress'],
      name: json['Name'],
      description: json['Description'],
      enableDHCP: json['EnableDHCP'],
      ipAddress: json['IPAddress'],
      subnetMask: json['SubnetMask'],
      gateway: json['Gateway'],
      preferredDNS: json['PreferredDNS'],
      standbyDNS: json['StandbyDNS'],
      points: pointList,
    );
  }
}

///wifi信息
class NetworkConnectWifi {
  String name;
  String password;

  NetworkConnectWifi({required this.name, required this.password});

  Map<String, dynamic> toJson() => {
        'Name': name,
        'Password': password,
      };
}

///Ip信息
class NetworkBase {
  String ipv4;

  NetworkBase({required this.ipv4});

  Map<String, dynamic> toJson() => {
        'Ipv4': ipv4,
      };
}
