<?php

namespace App\Services;

use App\Repositories\Eloquent\IngredientRepository;

class IngredientService
{
    public function __construct(
        protected IngredientRepository $ingredientRepository,
        protected LoggingService $loggingService
    ) {}

    public function getAll()
    {
        $this->loggingService->logInfo('Fetching all ingredients');
        return $this->ingredientRepository->all();
    }

    public function getActive()
    {
        $this->loggingService->logInfo('Fetching active ingredients');
        return $this->ingredientRepository->getActive();
    }

    public function find(int $id)
    {
        $this->loggingService->logInfo('Finding ingredient', ['id' => $id]);
        return $this->ingredientRepository->find($id);
    }

    public function findBySku(string $sku)
    {
        $this->loggingService->logInfo('Finding ingredient by SKU', ['sku' => $sku]);
        return $this->ingredientRepository->findBySku($sku);
    }

    public function search(string $term)
    {
        $this->loggingService->logInfo('Searching ingredients', ['term' => $term]);
        return $this->ingredientRepository->search($term);
    }

    public function create(array $data)
    {
        $this->loggingService->logInfo('Creating ingredient', ['data' => $data]);
        return $this->ingredientRepository->create($data);
    }

    public function update(int $id, array $data)
    {
        $this->loggingService->logInfo('Updating ingredient', ['id' => $id, 'data' => $data]);
        return $this->ingredientRepository->update($id, $data);
    }

    public function delete(int $id)
    {
        $this->loggingService->logInfo('Deleting ingredient', ['id' => $id]);
        return $this->ingredientRepository->delete($id);
    }

    public function getLowStock()
    {
        $this->loggingService->logInfo('Fetching low stock ingredients');
        return $this->ingredientRepository->getLowStock();
    }
}
