<?php

namespace App\Models;

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

class Product extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'sku',
        'category',
        'buying_price',
        'selling_price',
        'min_price',
        'stock',
    ];

    /**
     * Check if requested quantity is available in stock.
     */
    public function hasStock($quantity)
    {
        return $this->stock >= $quantity;
    }

    /**
     * Reduce stock after sale.
     */
    public function reduceStock($quantity)
    {
        $this->decrement('stock', $quantity);
    }

    public function billItems()
    {
        return $this->hasMany(BillItem::class);
    }
}
