import 'package:fcs/domain/entities/invoice.dart';
import 'package:fcs/domain/entities/payment.dart';
import 'package:fcs/helpers/api_helper.dart';
import 'package:fcs/helpers/firebase_helper.dart';
import 'package:logging/logging.dart';

class InvoiceDataProvider {
  final log = Logger('InvoiceDataProvider');
  static final InvoiceDataProvider instance = InvoiceDataProvider._();
  InvoiceDataProvider._();

  Future<void> createInvoice(Invoice invoice) async {
    return await requestAPI("/invoices", "POST",
        payload: invoice.toMap(), token: await getToken());
  }

  Future<void> updateInvoice(Invoice invoice) async {
    return await requestAPI("/invoices", "PUT",
        payload: invoice.toMap(), token: await getToken());
  }

  Future<void> cancelInvoice(Invoice invoice) async {
    return await requestAPI("/invoices/cancel", "PUT",
        payload: {"id": invoice.id}, token: await getToken());
  }

  Future<void> pay(Payment payment) async {
    return await requestAPI("/invoices/pay", "PUT",
        payload: payment.toMap(), token: await getToken());
  }

  Future<void> updatPaymentStatus(Payment payment) async {
    return await requestAPI("/invoices/pay/status", "PUT",
        payload: payment.toMap(), token: await getToken());
  }
}
