package com.eactive.eai.rms.onl.apim.approval.prodclient;

import com.eactive.eai.rms.common.base.OnlBaseAnnotationController;
import com.eactive.eai.rms.common.vo.GridResponse;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.SortDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequiredArgsConstructor
public class ProdClientManController extends OnlBaseAnnotationController {

    private final ProdClientManService prodClientManService;

    @GetMapping(value = "/onl/apim/approval/prodclient/clientMan.view")
    public void view() {
    }

    @GetMapping(value = "/onl/apim/approval/prodclient/clientMan.view", params = "cmd=DETAIL")
    public String detailView() {
        return "/onl/apim/approval/prodclient/clientManDetail";
    }

    @PostMapping(value = "/onl/apim/approval/prodclient/clientMan.json", params = "cmd=LIST")
    public ResponseEntity<GridResponse<ProdClientUI>> selectList(@SortDefault("clientname") Pageable pageable,
        ProdClientSearch clientSearch) {
        Page<ProdClientUI> page = prodClientManService.selectList(pageable, clientSearch);
        return ResponseEntity.ok(new GridResponse<>(page));
    }

    @PostMapping(value= "/onl/apim/approval/prodclient/clientMan.json",params = "cmd=LIST_DETAIL_COMBO")
    public ResponseEntity<Map<String, Object>> selectDetailCombo() throws Exception {
        Map<String, Object> map = prodClientManService.selectDetailCombo();
        return ResponseEntity.ok(map);
    }

    @PostMapping(value = "/onl/apim/approval/prodclient/clientMan.json", params = "cmd=DETAIL")
    public ResponseEntity<ProdClientUI> selectDetail(String clientId) {
        ProdClientUI clientUI = prodClientManService.selectDetail(clientId);
        return ResponseEntity.ok(clientUI);
    }

    @PostMapping(value = "/onl/apim/approval/prodclient/clientMan.json", params = "cmd=INSERT")
    public ResponseEntity<Void> insert(ProdClientUI clientUI) {
        prodClientManService.insert(clientUI);
        return ResponseEntity.ok().build();
    }

    @PostMapping(value = "/onl/apim/approval/prodclient/clientMan.json", params = "cmd=UPDATE")
    public ResponseEntity<Void> update(ProdClientUI clientUI) {
        prodClientManService.update(clientUI);
        return ResponseEntity.ok().build();
    }

    @PostMapping(value = "/onl/apim/approval/prodclient/clientMan.json", params = "cmd=DELETE")
    public ResponseEntity<Void> delete(String clientId) {
        prodClientManService.delete(clientId);
        return ResponseEntity.ok().build();
    }
}
