package dev.service;

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

import java.util.List;
import java.util.Scanner;

public class MenuService {

    public static final MenuItemDao menuItemDao = new MenuItemDao();

    public void showMenu() {

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

        System.out.println("=======================");
        System.out.println("==       MENU        ==");
        System.out.println("=======================");

        for (MenuItem item : items) {

            System.out.format("[%d] %s - $%.2f\n%s\nCategory: %s\n",
                    item.getId(),
                    item.getName(),
                    item.getPrice(),
                    item.getDescription(),
                    item.getCategory()
            );
        }

    }

    public void ShowPanel(User user) {

        OrderService orderService = new OrderService();

        while (true) {

            System.out.println("=======================");
            System.out.println("==      WELCOME      ==");
            System.out.println("=======================");
            System.out.println("""
                1.Place order
                2.Order history
                3.Logout
                """);


            Scanner scanner = new Scanner(System.in);

            int choice = scanner.nextInt();

            switch (choice) {

                case 1: {
                    orderService.placeOrder(user.getId());
                    break;
                }
                case 2: {

                    orderService.showOrderHistory(user.getId());
                    break;
                }
                case 3: {
                    System.out.println("goodbye, " + user.getUsername());
                   return;
                }
                default:{
                    System.out.println("invalid choice.enter a number between [1,3]");
                }
            }
        }

    }

}