<?php

namespace Modules\User\Controllers\Store;

use App\Http\Controllers\Controller;
use App\Models\Order;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\Request;
use App\Models\WebsiteVisitor;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
use Modules\Category\Models\Category;
use Modules\Order\Enums\OrderStatusEnum;
use Modules\Order\Services\OrderService;
use Modules\Product\Models\Product;
use Modules\Product\Services\ProductService;
use Modules\User\Enums\UserRoleEnum;
use Modules\User\Models\User;
use Modules\User\Services\UserService;
use Modules\Store\Services\StoreService;
use Modules\Store\Models\Store;

class DashboardController extends Controller
{

    public function __construct(
        private OrderService $orderService,
        private ProductService $productService
    ){}

    public function index(Request $request) :View
    {
        $today_date = date('Y-m-d');
        $today_orders_total = $this->orderService->totalProducts([
            'today'=>$today_date,
            'store_id'=>auth()->user()->store_id,
        ]);
        $month_orders_total = $this->orderService->totalProducts([
            'date'=>date('Y-m-').'01',
            'store_id'=>auth()->user()->store_id,
        ]);
        $year_orders_total = $this->orderService->totalProducts([
            'date'=>date('Y-').'01-01',
            'store_id'=>auth()->user()->store_id,
        ]);

        $today_orders_count = $this->orderService->get([
            'today'=>$today_date,
            'store_id'=>auth()->user()->store_id,
        ])->count();
        $month_orders_count = $this->orderService->get([
            'date'=>date('Y-m-').'01',
            'store_id'=>auth()->user()->store_id,
        ])->count();
        $year_orders_count = $this->orderService->get([
            'date'=>date('Y-').'01-01',
            'store_id'=>auth()->user()->store_id,
        ])->count();

        $latest_orders = $this->orderService->get([
            'paginate'=>10,
            'store_id'=>auth()->user()->store_id,
        ]);
        $most_sold_products = $this->productService->mostSold([
            'paginate'=>10,
            'store_id'=>auth()->user()->store_id,
        ]);
        return view('store.index',get_defined_vars());
    }
}
