package com.oqpo.api.web.controller.oper;

import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.oper.PopService;
import com.oqpo.api.web.dto.request.oper.pop.PopGridRequest;
import com.oqpo.api.web.dto.request.oper.pop.SavePopRequest;
import com.oqpo.api.web.dto.response.GridResponse;
import com.oqpo.api.web.dto.response.SaveResponse;
import com.oqpo.api.web.dto.response.oper.ntice.NticeResponse;
import com.oqpo.api.web.dto.response.oper.pop.LoginPopInfoResponse;
import com.oqpo.api.web.dto.response.oper.pop.PopResponse;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/api/pop")
public class PopController {
    @Autowired
    private PopService popService;

    /**
     * 설명 : 팝업 그리드 리스트
     *
     * @param popGridRequest
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 팝업 그리드 리스트")
    @PostMapping("/detail-grid-list")
    public ResponseEntity<GridResponse> detailGridList(@RequestBody @Valid PopGridRequest popGridRequest) throws Exception {
        return ResponseEntity.ok(popService.selectPopGridList(popGridRequest.getFromDt(), popGridRequest.getToDt(), popGridRequest.getSPopNm(), popGridRequest.toDTO(popGridRequest)));
    }

    /**
     * 설명 : 팝업 정보 저장
     *
     * @param userId
     * @param savePopRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "팝업정보 저장")
    @PostMapping("/save-pop")
    public ResponseEntity<SaveResponse> savePop(@ApiIgnore String userId, @RequestBody @Valid SavePopRequest savePopRequest) throws Exception {
        popService.savePop(userId, savePopRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }

    /**
     * 설명 : 팝업 정보
     *
     * @param popNo
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "popNo", value = "팝업번호", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "팝업 정보")
    @GetMapping("/info-pop")
    public ResponseEntity<PopResponse> infoPop(@RequestParam(value = "popNo") String popNo) throws Exception {
        return ResponseEntity.ok(popService.selectPopInfo(popNo));
    }

    /**
     * 설명 : 팝업 대상 정보 전달
     *
     * @param sViewTargetCd
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sViewTargetCd", value = "출력구분", required = false, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "팝업 오픈 정보")
    @GetMapping("/open-pop")
    public ResponseEntity<LoginPopInfoResponse> openPop(@RequestParam(value = "sViewTargetCd" , required = false) String sViewTargetCd) throws Exception {
        return ResponseEntity.ok(LoginPopInfoResponse.toDTO(popService.selectOpenPop(sViewTargetCd)) );

    }


}
