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

import com.eactive.eai.rms.common.base.OnlBaseAnnotationController;
import com.eactive.eai.rms.common.vo.GridResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
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;

@Controller
@RequiredArgsConstructor
public class PortalAppRequestManController extends OnlBaseAnnotationController {

    private final PortalAppRequestManService portalAppRequestManService;

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

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

    @PostMapping(value = "/onl/apim/approval/apprequest/prodAppRequestMan.json", params = "cmd=LIST")
    public ResponseEntity<GridResponse<AppRequestUI>> selectList(@SortDefault(value = "createdDate", direction = Sort.Direction.DESC) Pageable pageable,
        AppRequestUISearch appRequestUISearch) {
        Page<AppRequestUI> page = portalAppRequestManService.selectList(pageable, appRequestUISearch);
        return ResponseEntity.ok(new GridResponse<>(page));
    }

    @PostMapping(value = "/onl/apim/approval/apprequest/prodAppRequestMan.json", params = "cmd=DETAIL")
    public ResponseEntity<AppRequestUI> selectDetail(String id) {
        AppRequestUI portalApprovalUI = portalAppRequestManService.selectDetail(id);
        return ResponseEntity.ok(portalApprovalUI);
    }

    @PostMapping(value = "/onl/apim/approval/apprequest/prodAppRequestMan.json", params = "cmd=UPDATE")
    public ResponseEntity<AppRequestUI> update(AppRequestUI appRequestUI) {
        AppRequestUI portalApprovalUI = portalAppRequestManService.update(appRequestUI);
        return ResponseEntity.ok(portalApprovalUI);
    }

}
