package dev.service;

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

import java.util.List;

public class MenuService {

    private final MenuItemDao menuItemDao = new MenuItemDao();

    /** Loads every menu item so other parts of the app can use them. */
    public List<MenuItem> getMenu() {
        return menuItemDao.findAll();
    }

    /** Prints the whole menu to the console in a simple table. */
    public void showMenu() {

        List<MenuItem> items = menuItemDao.findAll();

        if (items.isEmpty()) {
            System.out.println("The menu is empty.");
            return;
        }

        System.out.println("---------------------------------------------");
        System.out.printf("%-4s %-20s %-10s %-10s%n", "ID", "Name", "Price", "Category");
        System.out.println("---------------------------------------------");

        for (MenuItem item : items) {
            String category = item.getCategory() == null ? "-" : item.getCategory();
            System.out.printf("%-4d %-20s $%-9.2f %-10s%n",
                    item.getId(), item.getName(), item.getPrice(), category);
        }

        System.out.println("---------------------------------------------");
    }

}
