<?php

namespace App\Http\Resources;

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

class RepaymentResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'credit_id' => (int)$this->credit_id,
            'credit_code' => $this->credit->code,
            'lender_id' => (int)$this->lender_id,
            'lender_code' => $this->lender->code,
            'lender_name' => $this->lender->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,
        ];
    }
}
