<?php

namespace App\Models;

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

class Purchase extends Model
{
    protected $guarded = [];

    // Relasi ke Tabel Anak (Item Barang)
    public function items(): HasMany
    {
        return $this->hasMany(PurchaseItem::class);
    }

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

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

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

    public function debtPayments(): HasMany
    {
        return $this->hasMany(DebtPayment::class, 'purchase_id');
    }
    public function payments()
    {
        return $this->hasMany(DebtPayment::class);
    }
    
}