import 'package:equatable/equatable.dart';

class ScreenInfo extends Equatable {
  final double widthPx;
  final double heightPx;
  final double density;
  final double widthDp;
  final double heightDp;
  final bool hasNotch;

  const ScreenInfo({
    required this.widthPx,
    required this.heightPx,
    required this.density,
    required this.widthDp,
    required this.heightDp,
    required this.hasNotch,
  });

  factory ScreenInfo.fromJson(Map<String, dynamic> json) {
    return ScreenInfo(
      widthPx: (json['widthPx'] as num).toDouble(),
      heightPx: (json['heightPx'] as num).toDouble(),
      density: (json['density'] as num).toDouble(),
      widthDp: (json['widthDp'] as num).toDouble(),
      heightDp: (json['heightDp'] as num).toDouble(),
      hasNotch: json['hasNotch'] as bool? ?? false,
    );
  }

  Map<String, dynamic> toJson() => {
        'widthPx': widthPx,
        'heightPx': heightPx,
        'density': density,
        'widthDp': widthDp,
        'heightDp': heightDp,
        'hasNotch': hasNotch,
      };

  @override
  List<Object?> get props => [widthPx, heightPx, density, widthDp, heightDp, hasNotch];
}

class DeviceContext extends Equatable {
  final String platform;
  final String brand;
  final String model;
  final String manufacturer;
  final bool isPhysicalDevice;
  final String osVersion;
  final int sdkInt;
  final String androidId;
  final ScreenInfo screen;
  final String appName;
  final String packageName;
  final String appVersion;
  final String buildNumber;
  final String buildMode;
  final String locale;
  final String timezone;
  final bool isDarkMode;
  final String networkType;
  final DateTime collectedAt;

  const DeviceContext({
    required this.platform,
    required this.brand,
    required this.model,
    required this.manufacturer,
    required this.isPhysicalDevice,
    required this.osVersion,
    required this.sdkInt,
    required this.androidId,
    required this.screen,
    required this.appName,
    required this.packageName,
    required this.appVersion,
    required this.buildNumber,
    required this.buildMode,
    required this.locale,
    required this.timezone,
    required this.isDarkMode,
    required this.networkType,
    required this.collectedAt,
  });

  factory DeviceContext.fromJson(Map<String, dynamic> json) {
    return DeviceContext(
      platform: json['platform'] as String,
      brand: json['brand'] as String,
      model: json['model'] as String,
      manufacturer: json['manufacturer'] as String,
      isPhysicalDevice: json['isPhysicalDevice'] as bool,
      osVersion: json['osVersion'] as String,
      sdkInt: json['sdkInt'] as int,
      androidId: json['androidId'] as String,
      screen: ScreenInfo.fromJson(json['screen'] as Map<String, dynamic>),
      appName: json['appName'] as String,
      packageName: json['packageName'] as String,
      appVersion: json['appVersion'] as String,
      buildNumber: json['buildNumber'] as String,
      buildMode: json['buildMode'] as String,
      locale: json['locale'] as String,
      timezone: json['timezone'] as String,
      isDarkMode: json['isDarkMode'] as bool,
      networkType: json['networkType'] as String,
      collectedAt: DateTime.parse(json['collectedAt'] as String),
    );
  }

  Map<String, dynamic> toJson() => {
        'platform': platform,
        'brand': brand,
        'model': model,
        'manufacturer': manufacturer,
        'isPhysicalDevice': isPhysicalDevice,
        'osVersion': osVersion,
        'sdkInt': sdkInt,
        'androidId': androidId,
        'screen': screen.toJson(),
        'appName': appName,
        'packageName': packageName,
        'appVersion': appVersion,
        'buildNumber': buildNumber,
        'buildMode': buildMode,
        'locale': locale,
        'timezone': timezone,
        'isDarkMode': isDarkMode,
        'networkType': networkType,
        'collectedAt': collectedAt.toIso8601String(),
      };

  @override
  List<Object?> get props => [platform, brand, model, manufacturer, isPhysicalDevice, osVersion, sdkInt, androidId, screen, appName, packageName, appVersion, buildNumber, buildMode, locale, timezone, isDarkMode, networkType, collectedAt];
}
