<?php

namespace App\Http\Controllers\Api\Reports;

use App\Domains\Conversations\Models\Conversation;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;

class ConversationsReportController extends Controller
{
    public function __invoke(): JsonResponse
    {
        $tenantId = request()->user()->tenant_id;

        return response()->json([
            'data' => [
                'backlogSize' => Conversation::query()->where('tenant_id', $tenantId)->where('status', 'open')->count(),
                'pendingCount' => Conversation::query()->where('tenant_id', $tenantId)->where('status', 'pending')->count(),
                'closedCount' => Conversation::query()->where('tenant_id', $tenantId)->where('status', 'closed')->count(),
                'unassignedCount' => Conversation::query()->where('tenant_id', $tenantId)->whereNull('assigned_user_id')->count(),
                'unreadCount' => Conversation::query()->where('tenant_id', $tenantId)->sum('unread_count'),
            ],
        ]);
    }
}
