<?php

namespace Modules\Admin\Services;

use Modules\Admin\Repositories\Interfaces\UserRepositoryInterface;
use Modules\Admin\Repositories\Interfaces\ProductRepositoryInterface;
use Modules\Admin\Repositories\Interfaces\CategoryRepositoryInterface;
use Modules\Admin\Repositories\Interfaces\OrderRepositoryInterface;
use Modules\Admin\Repositories\Interfaces\CartItemRepositoryInterface;
use Modules\Admin\Repositories\Interfaces\BasketItemRepositoryInterface;
use Modules\Admin\Repositories\Interfaces\PaymentMethodRepositoryInterface;
use Modules\Admin\Repositories\Interfaces\SaveTheFoodProductRepositoryInterface;
use Modules\Admin\Repositories\Interfaces\WeeklySpecialRepositoryInterface;

class DashboardService
{
    public function __construct(
        private UserRepositoryInterface $userRepository,
        private ProductRepositoryInterface $productRepository,
        private CategoryRepositoryInterface $categoryRepository,
        private OrderRepositoryInterface $orderRepository,
        private CartItemRepositoryInterface $cartItemRepository,
        private BasketItemRepositoryInterface $basketItemRepository,
        private PaymentMethodRepositoryInterface $paymentMethodRepository,
        private SaveTheFoodProductRepositoryInterface $saveTheFoodProductRepository,
        private WeeklySpecialRepositoryInterface $weeklySpecialRepository,
    ) {}

    public function getStats(): array
    {
        return [
            'users' => $this->userRepository->count(),
            'products' => $this->productRepository->count(),
            'categories' => $this->categoryRepository->count(),
            'orders' => $this->orderRepository->count(),
            'pending_orders' => $this->orderRepository->countByStatus('pending'),
            'paid_orders' => $this->orderRepository->countByStatus('paid'),
            'revenue' => $this->orderRepository->totalRevenue(),
            'cart_items' => $this->cartItemRepository->count(),
            'basket_items' => $this->basketItemRepository->count(),
            'payment_methods' => $this->paymentMethodRepository->count(),
            'save_the_food' => $this->saveTheFoodProductRepository->count(),
            'weekly_specials' => $this->weeklySpecialRepository->count(),
        ];
    }
}
