package dev.service;
import dev.dao.MenuItemDao;
import dev.model.MenuItem;
import java.lang.reflect.Field;
import java.util.List;

public class MenuService {
    private final MenuItemDao menuItemDao = new MenuItemDao();
    public void showMenu() {

        // TODO:
        // Display menu items
        List<MenuItem> items = menuItemDao.findAll();
        System.out.println("\n--- RESTAURANT MENU ---");
        if (items.isEmpty()){
            System.out.println("No items available.");
            return;
        }

        try {
            Field idField = MenuItem.class.getDeclaredField("id");
            Field nameField = MenuItem.class.getDeclaredField("name");
            Field priceField = MenuItem.class.getDeclaredField("price");
            Field descField = MenuItem.class.getDeclaredField("description");
            idField.setAccessible(true);
            nameField.setAccessible(true);
            priceField.setAccessible(true);
            descField.setAccessible(true);
            for (MenuItem item : items){
                System.out.printf("%d. %s - $%.2f (%s)\n", idField.get(item), nameField.get(item), priceField.get(item), descField.get(item) != null ? descField.get(item) : "No description");
            }
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
    }

}