package com.eactive.eai.rms.onl.manage.comm.codeMan;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
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.OnlBaseAnnotationController;
import com.eactive.eai.rms.common.vo.GridResponse;

@Controller
public class CodeManController extends OnlBaseAnnotationController {

	@Autowired
	private CodeManService codeManService;

	@GetMapping(value = "/onl/admin/common/codeMan.view")
	public void view() {
		// view
	}

	@GetMapping(value = "/onl/admin/common/codeMan.view", params = "cmd=GROUP POPUP")
	public String viewGroupPopup() {
		return "/onl/admin/common/codeManGroupPopup";
	}

	@GetMapping(value = "/onl/admin/common/codeMan.view", params = "cmd=POPUP")
	public String viewPopup() {
		return "/onl/admin/common/codeManPopup";
	}

	@PostMapping(value = "/onl/admin/common/codeMan.json", params = "cmd=LIST")
	public ResponseEntity<GridResponse<CodeGroupUI>> selectList(String searchName) {
		List<CodeGroupUI> codeGroupUI = codeManService.selectCodeGroupList(searchName);
		return ResponseEntity.ok(new GridResponse<>(codeGroupUI));
	}

	@PostMapping(value = "/onl/admin/common/codeMan.json", params = "cmd=LIST_TREE")
	public ResponseEntity<GridResponse<CodeUI>> selectCodeTreeList(String searchCodeGroup) {
		List<CodeUI> list = codeManService.selectCodeTreeList(searchCodeGroup);
		return ResponseEntity.ok(new GridResponse<>(list));
	}

	@PostMapping(value = "/onl/admin/common/codeMan.json", params = "cmd=INSERT_GROUP")
	public ResponseEntity<String> insertGroup(CodeGroupUI codeGroupUI) {
		codeManService.insertGroup(codeGroupUI);
		return ResponseEntity.ok().build();
	}

	@PostMapping(value = "/onl/admin/common/codeMan.json", params = "cmd=INSERT")
	public ResponseEntity<String> insert(CodeUI codeUI) {
		codeManService.insert(codeUI);
		return ResponseEntity.ok().build();
	}

	@PostMapping(value = "/onl/admin/common/codeMan.json", params = "cmd=UPDATE_GROUP")
	public ResponseEntity<String> updateGroup(CodeGroupUI codeGroupUI) {
		codeManService.updateGroup(codeGroupUI);
		return ResponseEntity.ok().build();
	}

	@PostMapping(value = "/onl/admin/common/codeMan.json", params = "cmd=UPDATE")
	public ResponseEntity<String> update(CodeUI codeUI) {
		codeManService.update(codeUI);
		return ResponseEntity.ok().build();
	}

	@PostMapping(value = "/onl/admin/common/codeMan.json", params = "cmd=DELETE_GROUP")
	public ResponseEntity<String> deleteGroup(CodeGroupUI codeGroupUI) {
		codeManService.deleteGroup(codeGroupUI);
		return ResponseEntity.ok().build();
	}

	@PostMapping(value = "/onl/admin/common/codeMan.json", params = "cmd=DELETE")
	public ResponseEntity<String> delete(CodeUI codeUI) {
		codeManService.delete(codeUI);
		return ResponseEntity.ok().build();
	}
}
