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

import com.eactive.eai.rms.common.base.BaseAnnotationController;
import com.eactive.eai.rms.common.vo.GridResponse;
import com.eactive.eai.rms.onl.common.exception.BizException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
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
public class PortalPartnershipManController extends BaseAnnotationController {
	private final PortalPartnershipManService portalPartnershipManService;

	@Autowired
	public PortalPartnershipManController(PortalPartnershipManService portalPartnershipManService){
		this.portalPartnershipManService = portalPartnershipManService;
	}

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

	@GetMapping(value = "/onl/apim/portalpartnership/portalPartnershipMan.view", params = "cmd=DETAIL")
	public String detailView() {
		return "/onl/apim/portalpartnership/portalPartnershipManDetail";
	}

	@PostMapping(value = "/onl/apim/portalpartnership/portalPartnershipMan.json", params = "cmd=LIST")
	public ResponseEntity<GridResponse<PortalPartnershipUI>> selectList(@SortDefault(sort = "createdDate", direction = Sort.Direction.DESC) Pageable pageable,
																  String searchBizSubject,  String searchBizDetail) {
		Page<PortalPartnershipUI> page = portalPartnershipManService.selectList(pageable, searchBizSubject, searchBizDetail);
		return ResponseEntity.ok(new GridResponse<>(page));
	}

	@PostMapping(value = "/onl/apim/portalpartnership/portalPartnershipMan.json", params = "cmd=DETAIL")
	public ResponseEntity<PortalPartnershipUI> selectDetail(String id) {
		PortalPartnershipUI portalPartnershipUI = portalPartnershipManService.selectDetail(id);
		return ResponseEntity.ok(portalPartnershipUI);
	}

	@PostMapping(value = "/onl/apim/portalpartnership/portalPartnershipMan.json", params = "cmd=UNMASK")
	public ResponseEntity<PortalPartnershipUI> selectDetailUnmask(String id,String reason) {
		if (StringUtils.isBlank(reason)) {
			throw new BizException("마스킹 해제 사유를 입력해 주세요.");
		}
		PortalPartnershipUI portalPartnershipUI = portalPartnershipManService.selectDetailUnmask(id);
		return ResponseEntity.ok(portalPartnershipUI);
	}

	@PostMapping(value = "/onl/apim/portalpartnership/portalPartnershipMan.json", params = "cmd=DELETE")
	public ResponseEntity<Void> delete(String id) {
		portalPartnershipManService.delete(id);
		return ResponseEntity.ok().build();
	}

	@PostMapping(value = "/onl/apim/portalpartnership/portalPartnershipMan.json", params = "cmd=DELETE_BULK")
	public ResponseEntity<Void> deleteBulk(String ids) {
		portalPartnershipManService.deleteBulk(ids);
		return ResponseEntity.ok().build();
	}

}
