package dev.service;

import dev.dao.MenuItemDao;
import dev.model.MenuItem;

import java.util.List;

public class MenuService {

    private final MenuItemDao menuDao;

    public MenuService() {
        this.menuDao = new MenuItemDao();
    }

    public void showMenu() {
        List<MenuItem> items = menuDao.findAll();

        if (items.isEmpty()) {
            System.out.println("No menu items available!");
            return;
        }

        System.out.println("\n        - Remy's Today Menu -\n");

        String currentCategory = "";
        for (MenuItem item : items) {
            String category = item.getCategory() != null ? item.getCategory() : "Other";

            if (!category.equals(currentCategory)) {
                currentCategory = category;
                System.out.println("\n[ " + currentCategory + " ]");
                System.out.println("----------------------------------------");
            }

            System.out.printf("%d. %-25s $%.2f\n",
                    item.getId(),
                    item.getName(),
                    item.getPrice()
            );
        }
        System.out.println("----------------------------------------\n");
    }

    public List<MenuItem> getAllMenuItems() {
        return menuDao.findAll();
    }

    public MenuItem getMenuItemById(int id) {
        return menuDao.findById(id);
    }
}