<?php

declare(strict_types=1);

namespace App\Http\Resources;

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

class ProjectFinanceResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'summary' => [
                'income' => (int) ($this['income'] ?? 0),
                'expense' => (int) ($this['expense'] ?? 0),
                'net' => (int) ($this['net'] ?? 0),
            ],
            'tabs' => [
                'total_expense' => (int) ($this['expense'] ?? 0),
                'total_income' => (int) ($this['income'] ?? 0),
                'net_income' => (int) ($this['net'] ?? 0),
            ],
            'report' => $this['report'] ?? [],
            'pie_chart' => $this['pie_chart'] ?? [],
            'status_chart' => $this['status_chart'] ?? [],
            'transactions' => WalletTransactionResource::collection($this['transactions'] ?? collect()),
            'invoices' => InvoiceResource::collection($this['invoices'] ?? collect()),
        ];
    }
}
