<?php

namespace App\Http\Resources;

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

class TreasuryEntryResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => (int)$this->id,
            'category_id' => (int)$this->category->id,
            'category_code' => $this->category->code,
            'category_title' => $this->category->title,
            'code' => $this->code,
            'date' => $this->date,
            'amount' => (double)$this->amount,
            'title' => $this->title,
            'description' => $this->description,
            'attachment_url' => $this->attachment ? Storage::url($this->attachment) : null,
            'is_valid' => $this->is_valid,
            'validation_date' => $this->validation_date,
        ];
    }
}
