import 'package:syncrow_web/pages/analytics/services/power_clamp_info/power_clamp_info_service.dart';
import 'package:syncrow_web/pages/device_managment/power_clamp/models/power_clamp_model.dart';
import 'package:syncrow_web/services/api/http_service.dart';

final class RemotePowerClampInfoService implements PowerClampInfoService {
  const RemotePowerClampInfoService(this._httpService);

  final HTTPService _httpService;

  @override
  Future<PowerClampModel> getInfo(String deviceId) async {
    try {
      final response = await _httpService.get(
        path: '/devices/$deviceId/functions/status',
        showServerMessage: true,
        expectedResponseModel: (data) {
          final json = data as Map<String, Object?>? ?? {};
          final mappedData = json['data'] as Map<String, Object?>? ?? {};
          return PowerClampModel.fromJson(mappedData);
        },
      );
      return response;
    } catch (e) {
      throw Exception('Failed to fetch power clamp info: $e');
    }
  }
}
