import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'inspection_device_state.dart';

class InspectionDeviceCubit extends Cubit<InspectionDeviceState> {
  InspectionDeviceCubit({required String deviceId})
      : super(InspectionDeviceState(
          deviceId: deviceId,
          deviceName: '',
          deviceType: '',
          deviceStatus: '',
          deviceModel: '',
          installLocation: '',
          area: '',
          responsiblePerson: '',
          lastInspectionTime: '',
          inspectionHistory: [],
          inspectionItems: [],
          icon: Icons.devices,
        )) {
    _loadDeviceData(deviceId);
  }

  void _loadDeviceData(String deviceId) {
    // TODO: 从API或本地数据库加载设备数据
    // 这里使用模拟数据
    final mockState = InspectionDeviceState(
      deviceId: deviceId,
      deviceName: '客厅主控网关',
      deviceType: '智能网关',
      deviceStatus: '正常',
      deviceModel: 'SmartHub Pro V2',
      installLocation: '客厅电视柜',
      area: '客厅',
      responsiblePerson: '张师傅',
      lastInspectionTime: '2024-01-15 14:30:00',
      inspectionHistory: [
        InspectionHistoryItem(
          inspectorName: '张师傅',
          inspectionTime: '2024-01-15 14:30:00',
          result: '通过',
          remark: '设备运行正常，各项指标正常',
        ),
      ],
      inspectionItems: [
        InspectionItem(
          name: '电源状态',
          value: '正常',
          result: '通过',
        ),
        InspectionItem(
          name: '网络连接',
          value: '稳定',
          result: '通过',
        ),
        InspectionItem(
          name: 'CPU使用率',
          value: '23%',
          result: '通过',
        ),
        InspectionItem(
          name: '内存占用',
          value: '45%',
          result: '通过',
        ),
      ],
      icon: Icons.wifi,
    );
    emit(mockState);
  }
}
