<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Invoice extends Model
{
    protected $fillable = [
        'school_id', 'student_id', 'fee_structure_id', 'invoice_number',
        'total_amount', 'paid_amount', 'status', 'term', 'academic_year', 'due_date'
    ];

    protected $casts = [
        'due_date' => 'date',
    ];

    public function school()
    {
        return $this->belongsTo(School::class);
    }

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

    public function feeStructure()
    {
        return $this->belongsTo(FeeStructure::class);
    }

    public function payments()
    {
        return $this->hasMany(Payment::class);
    }

    public function balance()
    {
        return $this->total_amount - $this->paid_amount;
    }
}
