<?php

namespace App\Repositories\Eloquent;

use App\Models\Ingredient;
use Illuminate\Database\Eloquent\Model;

class IngredientRepository extends BaseRepository
{
    protected function resolveModel(): Model
    {
        return new Ingredient();
    }

    public function getActive()
    {
        return $this->model->active()->get();
    }

    public function findBySku(string $sku): ?Ingredient
    {
        return $this->model->where('sku', $sku)->first();
    }

    public function search(string $term)
    {
        return $this->model->where('name', 'like', "%{$term}%")
            ->orWhere('sku', 'like', "%{$term}%")
            ->active()
            ->get();
    }

    public function getLowStock()
    {
        return $this->model->active()
            ->whereColumn('minimum_stock', '>', 'reorder_level')
            ->get();
    }
}
