import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/service/base_service.dart';
import 'package:diplomaticquarterapp/models/anicllary-orders/ancillary_order_list_model.dart';
import 'package:diplomaticquarterapp/models/anicllary-orders/ancillary_order_proc_model.dart';

class AncillaryOrdersService extends BaseService {
  List<AncillaryOrdersListModel> _ancillaryLists = List();
  List<AncillaryOrdersListModel> get ancillaryLists => _ancillaryLists;
  List<AncillaryOrdersListProcListModel> _ancillaryProcLists = List();
  List<AncillaryOrdersListProcListModel> get ancillaryProcLists =>
      _ancillaryProcLists;

  Future getOrders() async {
    Map<String, dynamic> body = Map();

    hasError = false;

    await baseAppClient.post(GET_ANCILLARY_ORDERS,
        onSuccess: (dynamic response, int statusCode) {
      _ancillaryLists = [];
      response['AncillaryOrderList'].forEach((item) {
        ancillaryLists.add(AncillaryOrdersListModel.fromJson(item));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }

  Future getOrdersDetails(appointmentNo, orderNo, projectID) async {
    Map<String, dynamic> body = Map();
    body['AppointmentNo_Vida'] = appointmentNo;
    body['OrderNo'] = orderNo;
    body['ProjectID'] = projectID;
    hasError = false;
    await baseAppClient.post(GET_ANCILLARY_ORDERS_DETAILS,
        onSuccess: (dynamic response, int statusCode) {
      _ancillaryProcLists = [];

      response['AncillaryOrderProcList'].forEach((item) {
        ancillaryProcLists.add(AncillaryOrdersListProcListModel.fromJson(item));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }
}
