<?php

declare(strict_types=1);

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * @deprecated Prefer DashboardController ApiResponse payload.
 * Kept for backward compatibility if anything still wraps stats alone.
 */
class UserDashboardResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        if (is_array($this->resource) && array_key_exists('stats', $this->resource)) {
            return $this->resource;
        }

        return [
            'active_projects_count' => (int) ($this['active_projects_count'] ?? 0),
            'completed_projects_count' => (int) ($this['completed_projects_count'] ?? 0),
            'total_investment' => (int) ($this['total_investment'] ?? 0),
            'wallet_balance' => (int) ($this['wallet_balance'] ?? 0),
            'unread_notifications' => (int) ($this['unread_notifications'] ?? 0),
        ];
    }
}
