<?php

namespace App\Resources;

use Wibiesana\Padi\Core\Resource;

class SarprasPeminjamanResource extends Resource
{
    public function toArray($request): array
    {
        return [
            'id' => $this->id,
            'kode_transaksi' => $this->kode_transaksi,
            'item_id' => $this->item_id,
            'peminjam_id' => $this->peminjam_id,
            'petugas_id' => $this->petugas_id,
            'tanggal_pinjam' => $this->tanggal_pinjam,
            'tanggal_rencana_kembali' => $this->tanggal_rencana_kembali,
            'tanggal_kembali' => $this->tanggal_kembali,
            'jumlah_pinjam' => $this->jumlah_pinjam,
            'keperluan' => $this->keperluan,
            'status' => $this->status,
            'denda' => $this->denda,

            // Relations
            'item' => $this->whenLoaded('item'),
            'peminjam' => $this->whenLoaded('peminjam'),
            'petugas' => $this->whenLoaded('petugas'),

            // Flattened Fields
            'item_name' => $this->item['nama_barang'] ?? null,
            'peminjam_name' => $this->peminjam['nama_lengkap'] ?? null,
            'petugas_name' => $this->petugas['nama_lengkap'] ?? null,

        ];
    }
}