package cokr.xit.ens.modules.common.ctgy.intgrnnoti.presentation;

import cokr.xit.ens.core.aop.EnsResponseVO;
import cokr.xit.ens.modules.common.ctgy.intgrnnoti.model.IntgrnNotiAcceptReqDTO;
import cokr.xit.ens.modules.common.ctgy.intgrnnoti.service.IntgrnNotiService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Tag(name = "IntgrnNotiController")
@Slf4j
@RestController
@RequiredArgsConstructor
public class IntgrnNotiController {

    private final IntgrnNotiService intgrnNotiService;


    @Operation(summary = "접수")
    @PostMapping(value = "/intgrn/noti/accept", produces = MediaType.APPLICATION_JSON_VALUE)
//    public ResponseEntity<EnsResponseVO> accept(@Validated @RequestBody IntgrnNotiAcceptReqDTO reqDTO, BindingResult bindingResult){
    public ResponseEntity<EnsResponseVO> accept(@RequestBody IntgrnNotiAcceptReqDTO reqDTO){

        EnsResponseVO responseVO = intgrnNotiService.accept(reqDTO);


        return new ResponseEntity<EnsResponseVO>(responseVO, HttpStatus.OK);
    }



    @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
            @Content(mediaType = "application/json", examples = {
                    @ExampleObject(name = "Sample Example..."
                            , summary = "제작"
                            , value = "{\"intSendMastId\": 1}")
            })
    })
    @Operation(summary = "제작")
//    @PutMapping(value = "/intgrn/noti/make", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/intgrn/noti/make", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> make(@RequestBody Map<String, Long> mParam){

        EnsResponseVO responseVO = intgrnNotiService.remake(mParam.get("intSendMastId"));

        return new ResponseEntity<EnsResponseVO>(responseVO, HttpStatus.OK);
    }



    @Operation(summary = "제작(일괄)")
//    @PutMapping(value = "/intgrn/noti/make/all", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/intgrn/noti/make/all", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> makeAll(){

        EnsResponseVO responseVO = intgrnNotiService.makeAll();

        return new ResponseEntity<EnsResponseVO>(responseVO, HttpStatus.OK);
    }


    @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
            @Content(mediaType = "application/json", examples = {
                    @ExampleObject(name = "Sample Example..."
                            , summary = "(대량)전송요청"
                            , value = "{\"intSendMastId\": 1}")
            })
    })
    @Operation(summary = "(대량)전송요청")
    @PostMapping(value = "/intgrn/noti/send/bulk", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> sendBulk(@RequestBody Map<String, Long> mParam){
        EnsResponseVO responseVO = intgrnNotiService.sendBulk(mParam.get("intSendMastId"));

        return new ResponseEntity<EnsResponseVO>(responseVO, HttpStatus.OK);
    }

    @Operation(summary = "(대량)전송요청 일괄")
    @PostMapping(value = "/intgrn/noti/send/bulk/all", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> sendBulkAll(){
        EnsResponseVO responseVO = intgrnNotiService.sendBulkAll();

        return new ResponseEntity<EnsResponseVO>(responseVO, HttpStatus.OK);
    }


    @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
            @Content(mediaType = "application/json", examples = {
                    @ExampleObject(name = "Sample Example..."
                            , summary = "(대량)문서상태 갱신"
                            , value = "{\"intSendMastId\": 1}")
            })
    })
    @Operation(summary = "(대량)문서상태 갱신")
//    @PutMapping(value = "/intgrn/noti/stat/bulk", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/intgrn/noti/stat/bulk", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> statBulk(@RequestBody Map<String, Long> mParam){

        EnsResponseVO responseVO = intgrnNotiService.statBulk(mParam.get("intSendMastId"));

        return new ResponseEntity<EnsResponseVO>(responseVO, HttpStatus.OK);
    }

    @Operation(summary = "(대량)문서상태 일괄 갱신")
//    @PutMapping(value = "/intgrn/noti/stat/bulk/all", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/intgrn/noti/stat/bulk/all", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> statBulkAll(){

        EnsResponseVO responseVO = intgrnNotiService.statBulkAll();

        return new ResponseEntity<EnsResponseVO>(responseVO, HttpStatus.OK);
    }



    @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
            @Content(mediaType = "application/json", examples = {
                    @ExampleObject(name = "Sample Example..."
                            , summary = "전송결과 가져오기"
                            , value = "{\"intSendMastId\": 1}")
            })
    })
    @Operation(summary = "전송결과 가져오기")
    @PostMapping(value = "/intgrn/noti/send/result/provide", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> sendResultProvide(@RequestBody Map<String, Long> mParam){

        EnsResponseVO responseVO = intgrnNotiService.sendResultProvide(mParam.get("intSendMastId"));


        return new ResponseEntity<EnsResponseVO>(responseVO, HttpStatus.OK);
    }


    @Operation(summary = "문서상태 마감처리")
//    @PutMapping(value = "/intgrn/noti/stat/bulk/all", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/intgrn/noti/stat/closed", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> statClosed(){

        EnsResponseVO responseVO = intgrnNotiService.closed();

        return new ResponseEntity<EnsResponseVO>(responseVO, HttpStatus.OK);
    }
}
