<?php

namespace App\Http\Resources\Payments;

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

class PaymentResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => (int) ($this->resource['id'] ?? 0),
            'parent_id' => (int) ($this->resource['parent_id'] ?? 0),
            'invoice_id' => isset($this->resource['invoice_id']) ? (int) $this->resource['invoice_id'] : null,
            'total_amount' => (float) ($this->resource['total_amount'] ?? 0),
            'paid_amount' => (float) ($this->resource['paid_amount'] ?? 0),
            'balance' => (float) ($this->resource['balance'] ?? 0),
            'number_of_installments' => (int) ($this->resource['number_of_installments'] ?? 0),
            'transaction_id' => $this->resource['transaction_id'] ?? null,
            'payment_method' => $this->resource['payment_method'] ?? null,
            'payment_date' => $this->resource['payment_date'] ?? null,
            'status' => $this->resource['status'] ?? null,
            'semester' => $this->resource['semester'] ?? null,
            'school_year' => $this->resource['school_year'] ?? null,
            'created_at' => $this->resource['created_at'] ?? null,
            'updated_at' => $this->resource['updated_at'] ?? null,
        ];
    }
}
