<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class FeeChallanItem extends Model
{
    protected $fillable = [
        'fee_challan_id', 'student_id', 'fee_type_id', 'amount', 'discount', 'fine', 'detail',
    ];

    protected function casts(): array
    {
        return ['amount' => 'decimal:2', 'discount' => 'decimal:2', 'fine' => 'decimal:2'];
    }

    public function challan(): BelongsTo
    {
        return $this->belongsTo(FeeChallan::class, 'fee_challan_id');
    }

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

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

    public function getNetAttribute(): float
    {
        return (float) $this->amount - (float) $this->discount + (float) $this->fine;
    }
}
