<?php

namespace App\Models;

use App\Models\Concerns\Auditable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class BookLoan extends Model
{
    use Auditable, SoftDeletes;

    protected $fillable = [
        'book_id',
        'student_id',
        'loaned_on',
        'due_on',
        'returned_on',
        'status',
        'fine_amount',
        'issued_by',
    ];

    protected function casts(): array
    {
        return [
            'loaned_on' => 'date',
            'due_on' => 'date',
            'returned_on' => 'date',
            'fine_amount' => 'decimal:2',
        ];
    }

    public function book(): BelongsTo
    {
        return $this->belongsTo(Book::class);
    }

    public function student(): BelongsTo
    {
        return $this->belongsTo(Student::class);
    }

    public function issuedBy(): BelongsTo
    {
        return $this->belongsTo(Staff::class, 'issued_by');
    }
}
