<?php

declare(strict_types=1);

namespace App\Models;

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

class Ingredient extends Model
{
    protected $fillable = [
        'name',
        'unit',
        'purchase_unit',
        'usage_unit',
        'conversion_ratio',
        'purchase_price',
    ];

    /**
     * Get the recipes / BOM using this ingredient.
     */
    public function recipes(): HasMany
    {
        return $this->hasMany(Recipe::class);
    }

    /**
     * Get the outlet stock records for this ingredient.
     */
    public function outletIngredients(): HasMany
    {
        return $this->hasMany(OutletIngredient::class);
    }

    /**
     * Get the outlets tracking this ingredient.
     */
    public function outlets(): BelongsToMany
    {
        return $this->belongsToMany(Outlet::class, 'outlet_ingredients')
            ->withPivot('stock_qty', 'threshold_qty')
            ->withTimestamps();
    }
}
