package com.utopiaindustries.restcontroller;

import com.utopiaindustries.model.ctp.Bundle;

import com.utopiaindustries.model.ctp.MasterBundle;
import com.utopiaindustries.service.BundleService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping( "/rest/bundles" )
public class BundleRestController {

    private final BundleService bundleService;

    public BundleRestController(BundleService bundleService) {
        this.bundleService = bundleService;
    }

    @GetMapping("/search")
    public List<Bundle> searchBundles( @RequestParam String term ) {
        return bundleService.getBundleByIdAndItemIdAndSku( term );
    }

    @GetMapping( "/master/search" )
    public List<MasterBundle> searchMasterBundle( @RequestParam String term,
                                                  @RequestParam boolean received ){
        return bundleService.getMasterBundleByIdTerm( term, received );
    }

    @GetMapping( "/find-by-master/{masterId}" )
    public List<Bundle> findByMasterBarcode( @PathVariable("masterId") long masterId ){
        return bundleService.findBundlesByMasterId( masterId );
    }

}
