import 'mock/cabin_mock_data.dart';
import 'package:laki_icu_app/models/bo/cabin_detail_response.dart';
import 'package:laki_icu_app/utils/constants.dart';
import 'package:laki_icu_app/utils/http/dio_request.dart';
import 'package:laki_icu_app/utils/http/response_model.dart';

class CabinRepository {
  CabinRepository._();

  static final CabinRepository instance = CabinRepository._();

  /// 获取舱详情
  ///
  /// [carbinSn] 舱序列号（设备 SN）
  Future<ResponseModel<CabinDetailResponse>> getCabinDetail(
    String carbinSn,
  ) {
    if (Constants.useMockData) {
      return _mockCabinDetail();
    }
    return DioRequest.instance.get<CabinDetailResponse>(
      '/icu/detail',
      queryParameters: {'carbinSn': carbinSn},
      fromJsonT: (data) =>
          CabinDetailResponse.fromJson(data as Map<String, dynamic>),
    );
  }

  Future<ResponseModel<CabinDetailResponse>> _mockCabinDetail() async {
    await Future.delayed(const Duration(milliseconds: 300));
    return ResponseModel<CabinDetailResponse>(
      code: 200,
      msg: '获取舱详情成功（mock）',
      data: CabinMockData.getMockCabinDetail(),
      uuid: 'mock_uuid_${DateTime.now().millisecondsSinceEpoch}',
      success: true,
      timestamp: DateTime.now().millisecondsSinceEpoch,
    );
  }
}
