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

import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.oper.MailFormService;
import com.oqpo.api.service.oper.PopService;
import com.oqpo.api.web.dto.request.oper.mailform.MailFormGridRequest;
import com.oqpo.api.web.dto.request.oper.mailform.SaveMailFormRequest;
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.mailform.MailFormResponse;
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/mailform")
public class MailFormController {
    @Autowired
    private MailFormService mailFormService;

    /**
     * 설명 : 메일양식 그리드 리스트
     *
     * @param mailFormGridRequest
     * @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 MailFormGridRequest mailFormGridRequest) throws Exception {
        return ResponseEntity.ok(mailFormService.selectMailFormGridList(mailFormGridRequest.getSMailFormNm(),mailFormGridRequest.getSMailStatusCd(), mailFormGridRequest.toDTO(mailFormGridRequest)));
    }

    /**
     * 설명 : 메일양식 정보 저장
     *
     * @param userId
     * @param saveMailFormRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "메일양식정보 저장")
    @PostMapping("/save-mailform")
    public ResponseEntity<SaveResponse> saveUser(@ApiIgnore String userId, @RequestBody @Valid SaveMailFormRequest saveMailFormRequest) throws Exception {
        mailFormService.saveMailForm(userId, saveMailFormRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }

    /**
     * 설명 : 메일양식 정보
     *
     * @param mailFormNo
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "mailFormNo", value = "메일양식번호", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "메일양식 정보")
    @GetMapping("/info-mailForm")
    public ResponseEntity<MailFormResponse> infoMailForm(@RequestParam(value = "mailFormNo") String mailFormNo) throws Exception {
        return ResponseEntity.ok(mailFormService.selectMailFormInfo(mailFormNo));
    }


}
