package incheon.ags.pss.edit.smlt.web;

import java.util.List;

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 org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import incheon.ags.pss.edit.smlt.service.VRService;
import incheon.ags.pss.edit.smlt.vo.VrRcdHistVO;
import incheon.com.cmm.api.DefaultApiResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * VR 뷰어 관리 컨트롤러
 * @author (User)
 */
@Controller
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/pss/simulation/vr")
public class VRController {

    private final VRService vrService;

    /**
     * VR 기록 목록 조회 (JSON)
     * @param bizNo 안건지도 번호
     * @return List<VrRcdHistVO>
     * @throws Exception
     */
    @GetMapping("/list.do")
    @ResponseBody
    public List<VrRcdHistVO> selectVrRecordList(@RequestParam Long smltNo) throws Exception {
    	return vrService.selectVrRecordList(smltNo);
    }
    
    /**
     * VR 위치 기록 (저장)
     * @param vo VrRcdHistVO
     * @throws Exception
     */
    @PostMapping("/record.do")
    public ResponseEntity<DefaultApiResponse> recordVrPosition(@RequestBody VrRcdHistVO vo) throws Exception {
    	
//    	LoginVO loginVO = (LoginVO) authentication.getPrincipal();
//    	String loginUserId = loginVO.getUserId();
//    	vo.setFrstRegId(loginUserId);
//    	vo.setLastMdfcnId(loginUserId);
    	
    	vrService.recordVrPosition(vo);
    	
    	return ResponseEntity.ok(
                DefaultApiResponse.success(null, "위치가 기록되었습니다.")
            );
    }
    
    /**
     * VR 기록 삭제
     * @param rcdNo 기록 번호
     * @throws Exception
     */
    @PostMapping("/delete.do")
    public ResponseEntity<DefaultApiResponse> deleteVrRecord(@RequestParam String rcdNo) throws Exception {
		vrService.deleteVrRecord(rcdNo);
		
		return ResponseEntity.ok(
	            DefaultApiResponse.success(null, "삭제가 완료되었습니다.")
	        );
    }
}