import { CartDomainService } from '@/domain/services/CartDomainService';
import { DeliveryFeeService } from '@/domain/services/DeliveryFeeService';
import { CartSummary } from '@/application/dtos/CartSummary';
import { ICartRepository } from '@/application/ports/ICartRepository';

/**
 * USE CASE — Cart totals with delivery fee (single business rule path)
 */
export class GetCartSummaryUseCase {
  constructor(private readonly cart: ICartRepository) {}

  execute(): CartSummary {
    const items = this.cart.getItems();
    const subtotal = CartDomainService.calculateSubtotal(items);
    const deliveryFee = DeliveryFeeService.calculateDeliveryFee(subtotal);

    return {
      subtotal,
      deliveryFee,
      grandTotal: subtotal + deliveryFee,
      itemCount: CartDomainService.calculateItemCount(items),
      isFreeDelivery: DeliveryFeeService.isFreeDelivery(subtotal),
    };
  }
}