import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
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/fault_description.dart';

class FaultDescriptionProvider extends ChangeNotifier {

  int? _stateCode;

  int? get stateCode => _stateCode;

  bool _loading = false;

  bool get isLoading => _loading;

  set isLoading(bool isLoading) {
    _loading = isLoading;
    notifyListeners();
  }
  Future<List<FaultDescription>> getFaultDescriptionList({num? assetId}) async {
    late Response response;
    try {

        response = await ApiManager.instance.get(URLs.getFaultDescription+"?assetId=$assetId",);
      List<FaultDescription> list = [];
      if (response.statusCode >= 200 && response.statusCode < 300) {
        // client's request was successfully received
        List faultListJson = json.decode(response.body)["data"];

        list = faultListJson.map((fault) => FaultDescription.fromJson(fault)).toList();
      }
      return list;
    } catch (error) {
      return [];
    }
  }
}
