import 'package:equatable/equatable.dart';
import 'inspection_device_bo.dart';

class InspectionHistoryListBO extends Equatable {
  final int total;
  final InspectionHistoryTabCountBO tabCount;
  final InspectionHistoryDeviceInfoBO deviceInfo;
  final List<InspectionHistoryRecordBO> rows;

  const InspectionHistoryListBO({
    required this.total,
    required this.tabCount,
    required this.deviceInfo,
    required this.rows,
  });

  factory InspectionHistoryListBO.fromJson(Map<String, dynamic> json) {
    final rows = json['rows'] as List<dynamic>? ?? [];
    return InspectionHistoryListBO(
      total: int.tryParse(json['total']?.toString() ?? '') ?? 0,
      tabCount: InspectionHistoryTabCountBO.fromJson(
          json['tabCount'] as Map<String, dynamic>? ?? {}),
      deviceInfo: InspectionHistoryDeviceInfoBO.fromJson(
          json['deviceInfo'] as Map<String, dynamic>? ?? {}),
      rows: rows
          .map((e) => InspectionHistoryRecordBO.fromJson(
              e as Map<String, dynamic>))
          .toList(),
    );
  }

  @override
  List<Object?> get props => [total, tabCount, deviceInfo, rows];
}

class InspectionHistoryTabCountBO extends Equatable {
  final int total;
  final int passCount;
  final int warnCount;
  final int failCount;

  const InspectionHistoryTabCountBO({
    required this.total,
    required this.passCount,
    required this.warnCount,
    required this.failCount,
  });

  factory InspectionHistoryTabCountBO.fromJson(Map<String, dynamic> json) {
    return InspectionHistoryTabCountBO(
      total: int.tryParse(json['total']?.toString() ?? '') ?? 0,
      passCount: int.tryParse(json['passCount']?.toString() ?? '') ?? 0,
      warnCount: int.tryParse(json['warnCount']?.toString() ?? '') ?? 0,
      failCount: int.tryParse(json['failCount']?.toString() ?? '') ?? 0,
    );
  }

  @override
  List<Object?> get props => [total, passCount, warnCount, failCount];
}

class InspectionHistoryDeviceInfoBO extends Equatable {
  final int deviceId;
  final String deviceName;
  final String deviceIcon;

  const InspectionHistoryDeviceInfoBO({
    required this.deviceId,
    required this.deviceName,
    required this.deviceIcon,
  });

  factory InspectionHistoryDeviceInfoBO.fromJson(Map<String, dynamic> json) {
    return InspectionHistoryDeviceInfoBO(
      deviceId: int.tryParse(json['deviceId']?.toString() ?? '') ?? 0,
      deviceName: json['deviceName'] as String? ?? '',
      deviceIcon: json['deviceIcon'] as String? ?? '',
    );
  }

  @override
  List<Object?> get props => [deviceId, deviceName, deviceIcon];
}

class InspectionHistoryRecordBO extends Equatable {
  final int inspectId;
  final String inspectorName;
  final String inspectTime;
  final String inspectStatus;
  final String remark;
  final List<InspectionItemBO> itemsDetail;

  const InspectionHistoryRecordBO({
    required this.inspectId,
    required this.inspectorName,
    required this.inspectTime,
    required this.inspectStatus,
    required this.remark,
    required this.itemsDetail,
  });

  factory InspectionHistoryRecordBO.fromJson(Map<String, dynamic> json) {
    final items = json['itemsDetail'] as List<dynamic>? ?? [];
    return InspectionHistoryRecordBO(
      inspectId: int.tryParse(json['inspectId']?.toString() ?? '') ?? 0,
      inspectorName: json['inspectorName'] as String? ?? '',
      inspectTime: json['inspectTime'] as String? ?? '',
      inspectStatus: json['inspectStatus'] as String? ?? '',
      remark: json['remark'] as String? ?? '',
      itemsDetail: items
          .map((e) =>
              InspectionItemBO.fromJson(e as Map<String, dynamic>))
          .toList(),
    );
  }

  @override
  List<Object?> get props => [
        inspectId,
        inspectorName,
        inspectTime,
        inspectStatus,
        remark,
        itemsDetail,
      ];
}