<?php

declare(strict_types=1);

namespace App\Http\Resources;

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

class ProjectOverviewResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'active_count' => $this['active_count'] ?? 0,
            'completed_count' => $this['completed_count'] ?? 0,
            'total_investment' => (int) ($this['total_investment'] ?? 0),
            'total_profit' => (int) ($this['total_profit'] ?? 0),
            'profit_percent' => (float) ($this['profit_percent'] ?? 0),
            'profit_series' => $this['profit_series'] ?? [],
            'loss_series' => $this['loss_series'] ?? [],
            'tooltip' => $this['tooltip'] ?? null,
            'projects' => ProjectSummaryResource::collection($this['projects'] ?? collect()),
        ];
    }
}
