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

import com.eactive.eai.rms.data.entity.onl.apim.template.MessageTemplateSearch;
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 com.eactive.eai.rms.common.base.BaseAnnotationController;
import com.eactive.eai.rms.common.vo.GridResponse;

import lombok.RequiredArgsConstructor;

@Controller
@RequiredArgsConstructor
public class MessageTemplateManController extends BaseAnnotationController{

    private final MessageTemplateManService messageTemplateManService;

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

	@GetMapping(value = "/onl/apim/template/messageTemplateMan.view", params = "cmd=DETAIL")
	public String detailNewView() {
		return "/onl/apim/template/messageTemplateManPopup";
	}

	@PostMapping(value = "/onl/apim/template/messageTemplateMan.json", params = "cmd=LIST")
	public ResponseEntity<GridResponse<MessageTemplateUI>> selectList(@SortDefault("messageName") Pageable pageable,
			MessageTemplateSearch messageTemplateSearch) {
		Page<MessageTemplateUI> page = messageTemplateManService.selectList(pageable, messageTemplateSearch);
		return ResponseEntity.ok(new GridResponse<>(page));
	}


	@PostMapping(value = "/onl/apim/template/messageTemplateMan.json", params = "cmd=DETAIL")
	public ResponseEntity<MessageTemplateUI> selectDetail(String id) {
	  MessageTemplateUI messageTemplateUI = messageTemplateManService.selectDetail(id);
		return ResponseEntity.ok(messageTemplateUI);
	}

	@PostMapping(value = "/onl/apim/template/messageTemplateMan.json", params = "cmd=INSERT")
	public ResponseEntity<String> insert(MessageTemplateUI messageTemplateUI) {
		messageTemplateManService.insert(messageTemplateUI);
		return ResponseEntity.ok().build();
	}

	@PostMapping(value = "/onl/apim/template/messageTemplateMan.json", params = "cmd=UPDATE")
	public ResponseEntity<String> update(MessageTemplateUI messageTemplateUI) {
		messageTemplateManService.update(messageTemplateUI);
		return ResponseEntity.ok().build();
	}

	@PostMapping(value = "/onl/apim/template/messageTemplateMan.json", params = "cmd=DELETE")
	public ResponseEntity<Void> delete(MessageTemplateUI messageTemplateUI) {
		messageTemplateManService.delete(messageTemplateUI.getMessageCode());
		return ResponseEntity.ok().build();
	}

}
