<?php

namespace App\Http\Resources\ExtraCharges;

use Illuminate\Http\Resources\Json\JsonResource;

class ExtraChargeResource extends JsonResource
{
    public function toArray($request): array
    {
        $data = is_array($this->resource) ? $this->resource : $this->resource->toArray();

        return [
            'id' => (int) ($data['id'] ?? 0),
            'parent_id' => $data['parent_id'] ?? null,
            'invoice_id' => $data['invoice_id'] ?? null,
            'school_year' => $data['school_year'] ?? null,
            'semester' => $data['semester'] ?? null,
            'charge_type' => $data['charge_type'] ?? null,
            'title' => $data['title'] ?? null,
            'description' => $data['description'] ?? null,
            'amount' => $data['amount'] ?? null,
            'due_date' => $data['due_date'] ?? null,
            'status' => $data['status'] ?? null,
            'created_by' => $data['created_by'] ?? null,
            'created_at' => $data['created_at'] ?? null,
            'parent_name' => $data['parent_name'] ?? null,
            'invoice_number' => $data['invoice_number'] ?? null,
        ];
    }
}
