import 'package:flutter_modular/flutter_modular.dart';
import 'package:krow_data_connect/krow_data_connect.dart';

import 'data/repositories_impl/billing_repository_impl.dart';
import 'domain/repositories/billing_repository.dart';
import 'domain/usecases/get_current_bill_amount.dart';
import 'domain/usecases/get_invoice_history.dart';
import 'domain/usecases/get_pending_invoices.dart';
import 'domain/usecases/get_savings_amount.dart';
import 'domain/usecases/get_spending_breakdown.dart';
import 'presentation/blocs/billing_bloc.dart';
import 'presentation/pages/billing_page.dart';

/// Modular module for the billing feature.
class BillingModule extends Module {
  @override
  void binds(Injector i) {
    // Mock repositories (TODO: Replace with real implementations)
    i.addSingleton<FinancialRepositoryMock>(FinancialRepositoryMock.new);

    // Repositories
    i.addSingleton<BillingRepository>(
      () => BillingRepositoryImpl(
        financialRepository: i.get<FinancialRepositoryMock>(),
        dataConnect: ExampleConnector.instance,
      ),
    );

    // Use Cases
    i.addSingleton(GetCurrentBillAmountUseCase.new);
    i.addSingleton(GetSavingsAmountUseCase.new);
    i.addSingleton(GetPendingInvoicesUseCase.new);
    i.addSingleton(GetInvoiceHistoryUseCase.new);
    i.addSingleton(GetSpendingBreakdownUseCase.new);

    // BLoCs
    i.addSingleton<BillingBloc>(
      () => BillingBloc(
        getCurrentBillAmount: i.get<GetCurrentBillAmountUseCase>(),
        getSavingsAmount: i.get<GetSavingsAmountUseCase>(),
        getPendingInvoices: i.get<GetPendingInvoicesUseCase>(),
        getInvoiceHistory: i.get<GetInvoiceHistoryUseCase>(),
        getSpendingBreakdown: i.get<GetSpendingBreakdownUseCase>(),
      ),
    );
  }

  @override
  void routes(RouteManager r) {
    r.child('/', child: (_) => const BillingPage());
  }
}
