import 'package:agrilink_vocpro/core/state/result_state.dart';
import 'package:agrilink_vocpro/data/model/latest_data_response.dart';
import 'package:agrilink_vocpro/domain/service/app_service.dart';
import 'package:flutter/foundation.dart';

class TempProvider extends ChangeNotifier {
  TempProvider() {
    getTempData();
  }
  ResultState dataState = ResultState.initial;

  List<Dht> dataFetched = [];

  Future<void> getTempData() async {
    dataState = ResultState.loading;
    notifyListeners();
    try {
      final result =
          await AppService().getGrafikDataDht(metric: 'viciTemperature');
      if (result.data == null || result.data!.dht!.isEmpty) {
        dataState = ResultState.noData;
      } else {
        dataFetched = result.data!.dht ?? [];
        dataState = ResultState.hasData;
      }
    } catch (e) {
      if (kDebugMode) {
        print('Get Grafik Temperature Error: $e');
      }
      dataState = ResultState.error;
    }
    notifyListeners();
  }
}
