<?php

declare(strict_types=1);

namespace App\Http\Resources;

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

class WalletTransactionResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'user_id' => $this->user_id,
            'type' => $this->type,
            'amount' => (int) $this->amount,
            'balance_after' => $this->balance_after !== null ? (int) $this->balance_after : null,
            'description' => $this->description,
            'tracking_code' => $this->tracking_code,
            'status' => $this->status,
            'payment_id' => $this->payment_id,
            'project_id' => $this->project_id,
            'invoice_id' => $this->invoice_id,
            'meta' => $this->meta,
            'created_at' => $this->created_at?->toISOString(),
            'updated_at' => $this->updated_at?->toISOString(),
            'user' => new UserResource($this->whenLoaded('user')),
            'project' => new ProjectResource($this->whenLoaded('project')),
            'invoice' => new InvoiceResource($this->whenLoaded('invoice')),
            'payment' => new PaymentResource($this->whenLoaded('payment')),
        ];
    }
}
