package com.eactive.eai.rms.onl.apim.portalfaq;

import com.eactive.eai.rms.common.base.BaseAnnotationController;
import com.eactive.eai.rms.common.vo.GridResponse;
import com.eactive.eai.rms.data.entity.onl.apim.portalfaq.PortalFaqSearch;
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 PortalFaqManController extends BaseAnnotationController {

	private final PortalFaqManService portalFaqManService;

	@GetMapping(value = "/onl/apim/portalfaq/portalFaqMan.view")
	public void view() {
		// view
	}

	@GetMapping(value = "/onl/apim/portalfaq/portalFaqMan.view", params = "cmd=DETAIL")
	public String detailView() {
		return "/onl/apim/portalfaq/portalFaqManDetail";
	}


	@PostMapping(value = "/onl/apim/portalfaq/portalFaqMan.json", params = "cmd=LIST")
	public ResponseEntity<GridResponse<PortalFaqUI>> selectList(@SortDefault(sort = "createdDate", direction = Sort.Direction.DESC) Pageable pageable,
																 PortalFaqSearch portalFaqSearch) {
		Page<PortalFaqUI> page = portalFaqManService.selectList(pageable, portalFaqSearch);
		return ResponseEntity.ok(new GridResponse<>(page));
	}

	@PostMapping(value = "/onl/apim/portalfaq/portalFaqMan.json", params = "cmd=DETAIL")
	public ResponseEntity<PortalFaqUI> selectDetail(String id) {
		PortalFaqUI portalFaqUI = portalFaqManService.selectDetail(id);
		return ResponseEntity.ok(portalFaqUI);
	}

	@PostMapping(value = "/onl/apim/portalfaq/portalFaqMan.json", params = "cmd=INSERT")
	public ResponseEntity<String> insert(PortalFaqUI portalFaqUI) {
		portalFaqManService.insert(portalFaqUI);
		return ResponseEntity.ok().build();
	}

	@PostMapping(value = "/onl/apim/portalfaq/portalFaqMan.json", params = "cmd=UPDATE")
	public ResponseEntity<String> update(PortalFaqUI portalFaqUI) {
		portalFaqManService.update(portalFaqUI);
		return ResponseEntity.ok().build();
	}

	@PostMapping(value = "/onl/apim/portalfaq/portalFaqMan.json", params = "cmd=DELETE")
	public ResponseEntity<String> update(String id) {
		portalFaqManService.delete(id);
		return ResponseEntity.ok().build();
	}

}
