package com.utopiaindustries.restcontroller;

import com.utopiaindustries.dao.ctp.FinishedItemDAO;
import com.utopiaindustries.model.ctp.FinishedItem;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/rest/finished-items")
public class FinishedItemRestController {

    private final FinishedItemDAO finishedItemDAO;

    public FinishedItemRestController(FinishedItemDAO finishedItemDAO) {
        this.finishedItemDAO = finishedItemDAO;
    }

    @GetMapping("/search")
    public List<FinishedItem> searchFinishedItems(@RequestParam("term") String term,
                                                  @RequestParam("is-segregated") boolean isSegregated) {
        return finishedItemDAO.findByTerm(term, true);
    }

    @GetMapping("/search-packaging")
    public List<FinishedItem> searchFinishedItemsForPackaging(@RequestParam("term") String term,
                                                              @RequestParam("is-segregated") boolean isSegregated) {
        return finishedItemDAO.findByTermForPackaging(term, isSegregated, "APPROVED");
    }

    @GetMapping("/search-store")
    public List<FinishedItem> searchFinishedItemsForStore(@RequestParam("term") String term,
                                                              @RequestParam("is-segregated") boolean isSegregated) {
        return finishedItemDAO.findByTermForPackaging(term, isSegregated,"REJECT");
    }
}
