<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Storage;

class RestitutionResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'loan_id' => (int)$this->loan_id,
            'loan_code' => $this->loan->code,
            'borrower_id' => (int)$this->borrower_id,
            'borrower_code' => $this->borrower->code,
            'borrower_name' => $this->borrower->name(),
            'code' => $this->code,
            'amount' => (double)$this->amount,
            'date' => $this->date,
            'attachment_url' => $this->attachment ? Storage::url($this->attachment) : null,
            'is_valid' => $this->is_valid,
            'validation_date' => $this->validation_date,
        ];
    }
}
