<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;
use Inertia\Inertia;

class BusinessDashboardController extends Controller
{
    public function index()
    {
        $business = Auth::guard('business')->user();

        $todaySales = $business->sales()->whereDate('date', today())->sum('total_amount');
        $todayRepairs = $business->repairs()->whereDate('date', today())->sum('charge');
        $todayUnlocks = $business->unlockOrders()->whereDate('created_at', today())->count();
        $totalProfit = $business->sales()->sum('profit') + $business->repairs()->sum('charge');

        return Inertia::render('Business/Dashboard', [
            'stats' => [
                'today_sales' => $todaySales,
                'today_repairs' => $todayRepairs,
                'today_unlocks' => $todayUnlocks,
                'total_profit' => $totalProfit,
                'plan_type' => $business->plan_type,
                'plan_expiry' => $business->plan_expiry_date,
                'is_expired' => $business->isExpired(),
            ],
        ]);
    }
}