package com.utopiaindustries.restcontroller;

import com.utopiaindustries.model.ctp.PurchaseOrderCTP;
import com.utopiaindustries.model.uind.PurchaseOrder;
import com.utopiaindustries.service.PurchaseOrderCTPService;
import com.utopiaindustries.service.PurchaseOrderService;
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/purchase-orders" )
public class PurchaseOrderRestController {

    private final PurchaseOrderService purchaseOrderService;
    private final PurchaseOrderCTPService purchaseOrderCTPService;

    public PurchaseOrderRestController(PurchaseOrderService purchaseOrderService, PurchaseOrderCTPService purchaseOrderCTPService) {
        this.purchaseOrderService = purchaseOrderService;
        this.purchaseOrderCTPService = purchaseOrderCTPService;
    }

    /*
    *  search by term
    * */
    @GetMapping( "/search" )
    public List<PurchaseOrder> findByTerm(@RequestParam("term") String term ) {
        return purchaseOrderService.findByTerm( term );
    }

    /*
    *  search by term in ctp purchase order table
    * */
    @GetMapping( "/ctp-po-search" )
    public List<PurchaseOrderCTP> findByTermInCtpPurchaseOrderTable(@RequestParam("term") String term ) {
        return purchaseOrderCTPService.findByTerm( term );
    }
}
