import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';

class DeviceInfoPlus {
  static Future<Map<String, dynamic>> getDeviceInfo() async {
    final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
    Map<String, dynamic> deviceData = {};

    try {
      if (Platform.isAndroid) {
        AndroidDeviceInfo androidInfo = await deviceInfoPlugin.androidInfo;
        deviceData['platform'] = 'Android';
        deviceData['brand'] = androidInfo.brand;
        deviceData['model'] = androidInfo.model;
        deviceData['androidId'] = androidInfo.device;
        deviceData['version'] = androidInfo.version.release;
        deviceData['sdkVersion'] = androidInfo.version.sdkInt;
        deviceData['manufacturer'] = androidInfo.manufacturer;
        deviceData['isPhysicalDevice'] = androidInfo.isPhysicalDevice;
        deviceData['serialNumber'] = androidInfo.serialNumber;
        deviceData['fingerprint'] = androidInfo.fingerprint;
        deviceData['type'] = androidInfo.type;
        deviceData['data'] = androidInfo.data;
        deviceData['version'] = androidInfo.version;
        deviceData['tags'] = androidInfo.tags;
        deviceData['display'] = androidInfo.display;
      } else if (Platform.isIOS) {
        IosDeviceInfo iosInfo = await deviceInfoPlugin.iosInfo;
        deviceData['brand'] = 'Apple';
        deviceData['model'] = iosInfo.model;
        deviceData['systemName'] = iosInfo.systemName;
        deviceData['systemVersion'] = iosInfo.systemVersion;
        deviceData['utsname'] = iosInfo.utsname;
        deviceData['isPhysicalDevice'] = iosInfo.isPhysicalDevice;
        deviceData['identifierForVendor'] = iosInfo.identifierForVendor;
        deviceData['name'] = iosInfo.name;
        deviceData['localizedModel'] = iosInfo.localizedModel;
      } else if (Platform.isMacOS) {
        MacOsDeviceInfo macInfo = await deviceInfoPlugin.macOsInfo;
        deviceData['platform'] = 'macOS';
        deviceData['model'] = macInfo.model;
        deviceData['version'] = macInfo.systemGUID;
      } else if (Platform.isWindows) {
        WindowsDeviceInfo windowsInfo = await deviceInfoPlugin.windowsInfo;
        deviceData['platform'] = 'Windows';
        deviceData['manufacturer'] = windowsInfo.computerName;
        deviceData['version'] = windowsInfo.majorVersion;
        deviceData['deviceId'] = windowsInfo.deviceId;
        deviceData['userName'] = windowsInfo.userName;
        deviceData['productName'] = windowsInfo.productName;
        deviceData['installDate'] = windowsInfo.installDate;
        deviceData['productId'] = windowsInfo.productId;
        deviceData['numberOfCores'] = windowsInfo.numberOfCores;
        deviceData['systemMemoryInMegabytes'] =
            windowsInfo.systemMemoryInMegabytes;
      } else if (Platform.isLinux) {
        LinuxDeviceInfo linuxInfo = await deviceInfoPlugin.linuxInfo;
        deviceData['platform'] = 'Linux';
        deviceData['manufacturer'] = linuxInfo.name;
        deviceData['version'] = linuxInfo.version;
      }
    } catch (e) {
      print('Failed to get device info: $e');
    }

    return deviceData;
  }
}
