<?php

namespace App\Models;

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

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

    // Hubungan ke SaleItems (Anak)
    public function items(): HasMany
    {
        return $this->hasMany(SaleItem::class);
    }

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

    // ...
    public function customer(): BelongsTo
    {
        return $this->belongsTo(Customer::class);
    }
    // ...
    // Hubungan ke Cabang
    public function branch(): BelongsTo
    {
        return $this->belongsTo(Branch::class);
    }

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