<?php

namespace App\Models\Tenant;

use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Supplier extends Model
{
    use BelongsToTenant, SoftDeletes;

    protected $fillable = [
        'company_id', 'name', 'contact_name', 'phone', 'email', 'website',
        'pay_terms', 'delivery_days', 'rating', 'discount_pct',
        'categories', 'is_active', 'notes',
    ];

    protected $casts = [
        'categories' => 'array',
        'is_active' => 'boolean',
        'discount_pct' => 'decimal:2',
    ];

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

    public function parts(): HasMany
    {
        return $this->hasMany(Part::class, 'preferred_supplier_id');
    }
}
