<?php

namespace App\Models;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\SoftDeletes;

class Vendor extends BaseModel
{
    use SoftDeletes;

    protected $fillable = [
        'company_id','parent_id','code','name','contact_person',
        'email','phone','address','tax_id','currency_id',
        'payment_terms_days','bank_name','bank_account','bank_routing',
        'account_payable_id','is_active','notes','depth','path',
    ];

    protected $casts = ['is_active' => 'boolean'];

    public function company()    { return $this->belongsTo(Company::class); }
    public function currency()   { return $this->belongsTo(Currency::class); }
    public function apAccount()  { return $this->belongsTo(Account::class, 'account_payable_id'); }
    public function parent()     { return $this->belongsTo(Vendor::class, 'parent_id'); }
    public function children()   { return $this->hasMany(Vendor::class, 'parent_id'); }

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