package com.chantha.springdemo.service;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chantha.springdemo.model.Food;
import com.chantha.springdemo.repositories.FoodRepository;

@Service
public class FoodService {

	@Autowired
	private final FoodRepository foodRepository;

	public FoodService(FoodRepository foodRepository) {
		super();
		this.foodRepository = foodRepository;
	}
	public List<Food> findAllFoods(){
		return (List<Food>) foodRepository.findAll();
	}
	public Food findByID(Long id){
		return  foodRepository.findById(id).orElse(new Food());
	}
	public Food saveFood(Food food) {
		foodRepository.save(food);
		return food;
	}
	public List<Food> findFoodLimit(){
		return foodRepository.findFoodLimit();
	}
	public int deleteFoodById(int id) {
		 foodRepository.deleteById((long)id);
		 return id;
	}
}
