<?php

namespace App\Http\Resources\Payments;

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

class PaymentNotificationLogResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        $parent = $this->resource->parent ?? null;
        $parentName = $parent ? trim(($parent->firstname ?? '') . ' ' . ($parent->lastname ?? '')) : null;

        return [
            'id' => (int) ($this->resource->id ?? 0),
            'parent_id' => (int) ($this->resource->parent_id ?? 0),
            'parent_name' => $parentName,
            'invoice_id' => $this->resource->invoice_id ? (int) $this->resource->invoice_id : null,
            'school_year' => $this->resource->school_year ?? null,
            'period_year' => (int) ($this->resource->period_year ?? 0),
            'period_month' => (int) ($this->resource->period_month ?? 0),
            'type' => $this->resource->type ?? null,
            'to_email' => $this->resource->to_email ?? null,
            'cc_email' => $this->resource->cc_email ?? null,
            'status' => $this->resource->status ?? null,
            'error_message' => $this->resource->error_message ?? null,
            'balance_snapshot' => (float) ($this->resource->balance_snapshot ?? 0),
            'sent_at' => $this->resource->sent_at ?? null,
        ];
    }
}
