/// Payment Repository Implementation
///
/// Implements the payment repository interface.
library;

import 'package:worker/features/orders/data/datasources/payment_remote_datasource.dart';
import 'package:worker/features/orders/domain/entities/payment.dart';
import 'package:worker/features/orders/domain/repositories/payment_repository.dart';

/// Payment Repository Implementation
class PaymentRepositoryImpl implements PaymentRepository {
  const PaymentRepositoryImpl(this._remoteDataSource);

  final PaymentRemoteDataSource _remoteDataSource;

  @override
  Future<List<Payment>> getPaymentsList({
    int limitStart = 0,
    int limitPageLength = 0,
  }) async {
    try {
      final paymentsData = await _remoteDataSource.getPaymentsList(
        limitStart: limitStart,
        limitPageLength: limitPageLength,
      );
      // Convert Model → Entity
      return paymentsData.map((model) => model.toEntity()).toList();
    } catch (e) {
      throw Exception('Failed to get payments list: $e');
    }
  }

  @override
  Future<Payment> getPaymentDetail(String name) async {
    try {
      final paymentData = await _remoteDataSource.getPaymentDetail(name);
      // Convert Model → Entity
      return paymentData.toEntity();
    } catch (e) {
      throw Exception('Failed to get payment detail: $e');
    }
  }
}
