import '../repositories/inspection_device_repository.dart';
import '../models/bo/inspection_device_bo.dart';

class InspectionDeviceService {
  final InspectionDeviceRepository _repository;

  InspectionDeviceService({required InspectionDeviceRepository repository})
      : _repository = repository;

  Future<InspectionDeviceListBO> getList({
    required int pageSize,
    required int pageNum,
    int? roomId,
    String? runStatus,
  }) async {
    final result = await _repository.getList(
      pageSize: pageSize,
      pageNum: pageNum,
      roomId: roomId,
      runStatus: runStatus,
    );
    if (result.success && result.data != null) {
      return result.data!;
    }
    throw Exception(result.msg);
  }

  Future<DeviceDetailBO> getDetail(int deviceId) async {
    final result = await _repository.getDetail(deviceId);
    if (result.success && result.data != null) {
      return result.data!;
    }
    throw Exception(result.msg);
  }

  Future<InspectionStartResultBO> startInspection({
    required int deviceId,
    required int inspectorId,
  }) async {
    final result = await _repository.startInspection({
      'deviceId': deviceId,
      'inspectorId': inspectorId,
    });
    if (result.success && result.data != null) {
      return result.data!;
    }
    throw Exception(result.msg);
  }
}