import 'package:flutter/material.dart';
import 'package:initial_folder/models/counter_qna_like_model.dart';
import 'package:initial_folder/services/qna_service.dart';

enum ResultState { loading, noData, hasData, error }
enum ResultStateLike { loading, error }

class CounterQnaLikeProvider with ChangeNotifier {
  final String idQna;

  CounterQnaLikeProvider({required this.idQna}) {
    getLikeComment(idQna);
  }
  String _message = '';
  String get message => _message;
  ResultState? _state;
  ResultState? get state => _state;
  CounterLikeModel? _counterLikeModel;
  CounterLikeModel? get result => _counterLikeModel;
  set counterComment(CounterLikeModel? counterLikeModel) {
    _counterLikeModel = counterLikeModel;
    notifyListeners();
  }

  //Get Counter Like QNA
  Future<dynamic> getLikeComment(String idQna) async {
    try {
      _state = ResultState.loading;
      notifyListeners();
      CounterLikeModel counterLikeModel =
          await QnaService().getCounterLike(idQna);
      // print("Ini Cunter : ${counterLikeModel.data}");
      // ignore: unnecessary_null_comparison
      if (counterLikeModel.data != null) {
        print("ADA DATA");
        _state = ResultState.hasData;
        notifyListeners();
        return _counterLikeModel = counterLikeModel;
      } else {
        print("TIDAK ADA DATA");
        _state = ResultState.noData;
        notifyListeners();
        return _message = 'Tidak ada Data';
      }
    } catch (e) {
      _state = ResultState.error;
      print(e);
      notifyListeners();
      return _message = 'Error --> $e';
    }
  }
}
