<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Vendor extends Model
{
    use HasFactory;

    protected $fillable = [
        'name', 'phone', 'address', 'current_due', 'is_active',
    ];

    protected $casts = [
        'is_active' => 'boolean',
        'current_due' => 'decimal:2',
    ];

    public function purchases()
    {
        return $this->hasMany(Purchase::class);
    }

    public function ledgers()
    {
        return $this->hasMany(VendorLedger::class);
    }

    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }
}
