package com.utopiaindustries.restcontroller;

import com.utopiaindustries.dao.ctp.FinishedItemDAO;
import com.utopiaindustries.dao.ctp.StitchingOfflineItemDAO;
import com.utopiaindustries.model.ctp.StitchingOfflineItem;
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/stitching-offline-items" )
public class StitchingItemsRestController {

    private final FinishedItemDAO finishedItemDAO;

    private final StitchingOfflineItemDAO stitchingOfflineItemDAO;

    public StitchingItemsRestController(StitchingOfflineItemDAO stitchingOfflineItemDAO, FinishedItemDAO finishedItemDAO) {
        this.stitchingOfflineItemDAO = stitchingOfflineItemDAO;
        this.finishedItemDAO = finishedItemDAO;
    }

    @GetMapping( "/search" )
    public List<StitchingOfflineItem> searchFinishedItems(@RequestParam( "term") String term ){
        List<StitchingOfflineItem> items = stitchingOfflineItemDAO.findByTerm( term );
        return finishedItemDAO.findByBarcodeAndApprovedStatus(items);
    }
}
