package com.utopiaindustries.controller;

import com.utopiaindustries.service.InventoryService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping
public class InventoryTransactionController {

    private final InventoryService inventoryService;

    public InventoryTransactionController(InventoryService inventoryService) {
        this.inventoryService = inventoryService;
    }

    @GetMapping( "/inventory-transactions" )
    public String getInventoryTransactionsByAccount( @RequestParam( value = "account-id", required = true) long accountId,
                                                     Model model ){
        model.addAttribute("transactions", inventoryService.findTransactionByAccountId( accountId ));
        return "/cutting/inventory-transactions";
    }

    @GetMapping( "/inventory-summary" )
    public String getInventorySummaryByAccount( @RequestParam( value = "account-id", required = true) long accountId, Model model ){
        model.addAttribute("summaries", inventoryService.findItemSummaryByAccountId( accountId ));
        return "/cutting/inventory-summary";
    }
}
