import 'dart:convert';

import 'package:initial_folder/base_service.dart';
import 'package:initial_folder/helper/user_info.dart';
import 'package:initial_folder/models/detail_invoice_model.dart';
import 'package:http/http.dart' as http;

class DetailInvoiceService {
  Future<List<DataDetailInvoiceModel>> detailInvoice(String? orderId) async {
    String? token = await UsersInfo().getToken();

    Uri url = Uri.parse('$baseUrl/payment/invoice-detail/$orderId');

    http.Response response =
        await http.get(url, headers: headerWithToken(token!));
    List<DataDetailInvoiceModel> detailOrder = [];
    if (response.statusCode == 200) {
      print("BERHASIL COKKKK");
      var data = jsonDecode(response.body);
      print("Ini response berhasil get detail transaksi ${response.body}");

      var list = data['data'] as List;
      detailOrder =
          list.map((item) => DataDetailInvoiceModel.fromJson(item)).toList();

      return detailOrder;
    } else {
      print("GAGAL COKKKK");
      throw Exception('Data Transaksi Gagal Diambil');
    }
  }
}
