import 'dart:convert';

import 'package:http/http.dart';
import 'package:test_sa/providers/loading_list_notifier.dart';

import '../../controllers/api_routes/api_manager.dart';
import '../../controllers/api_routes/urls.dart';
import '../../models/lookup.dart';

class RetirementTypeProvider extends LoadingListNotifier<Lookup> {

  String? serviceRequestId;

  @override
  Future getData({int? id}) async {
    if (loading == true) return -2;
    print('get data called...');
    loading = true;
    notifyListeners();
    try {
      //TODO change this url only used for testing till ahmed make a new api.. getServiceReportReasonsTest replace with getServiceReportReasons
      Response response = await ApiManager.instance.get(URLs.getServiceReportRetirementType+"&serviceRequestId=$serviceRequestId");
      stateCode = response.statusCode;
      if (response.statusCode >= 200 && response.statusCode < 300) {
        List categoriesListJson = json.decode(response.body)["data"];
        items = categoriesListJson.map((item) => Lookup.fromJson(item)).toList();
      }
      loading = false;
      print('loading value in provider is $loading');
      notifyListeners();
      return response.statusCode;
    } catch (error) {
      loading = false;
      stateCode = -1;
      notifyListeners();
      return -1;
    }
  }
}