import 'dart:convert';
import 'dart:developer';

import 'package:http/http.dart';
import 'package:test_sa/controllers/api_routes/api_manager.dart';
import 'package:test_sa/controllers/api_routes/urls.dart';
import 'package:test_sa/models/lookup.dart';
import 'package:test_sa/modules/medical_gas_inspection/models/medical_gas_supplier_model.dart';
import 'package:test_sa/providers/loading_list_notifier.dart';

class MedicalGasSupplierProvider extends LoadingListNotifier<MedicalGasSupplierModel> {
  @override
  Future getData({int? id}) async {
    loading = true;
    notifyListeners();
    Response response;
    try {
      response = await ApiManager.instance.get(URLs.getMedicalGasSupplierList);
    } catch (error) {
      loading = false;
      stateCode = -1;
      notifyListeners();
      return -1;
    }
    stateCode = response.statusCode;
    if (response.statusCode >= 200 && response.statusCode < 300) {
      List listJson = json.decode(response.body)["data"];
      items = listJson.map((supplier) => MedicalGasSupplierModel.fromJson(supplier)).toList();
    }
    loading = false;
    notifyListeners();
    return response.statusCode;
  }
}
