<?php

namespace App\Models;

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

class Shop extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'owner',
        'phone',
        'city',
        'address',
        'due_balance',
    ];

    /**
     * Update due balance when a partial payment occurs.
     */
    public function addDue($amount)
    {
        $this->increment('due_balance', $amount);
    }

    /**
     * Reduce due balance when payment is collected.
     */
    public function reduceDue($amount)
    {
        $this->decrement('due_balance', $amount);
    }

    public function bills()
    {
        return $this->hasMany(Bill::class);
    }

    public function payments()
    {
        return $this->hasMany(Payment::class);
    }
}
