package cokr.xit.ens.modules.kkoalimtalk.presentation;

import cokr.xit.ens.core.aop.EnsResponseVO;
import cokr.xit.ens.modules.kkoalimtalk.model.KkoAlimtalkAcceptReqDTO;
import cokr.xit.ens.modules.kkoalimtalk.service.KkoAlimtalkService;
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 = "KkoAlimtalkController")
@Slf4j
@RequiredArgsConstructor
@RestController
public class KkoAlimtalkController {

    private final KkoAlimtalkService kkoAlimtalkService;


    @Operation(summary = "접수")
    @PostMapping(value = "/kko/alimtalk/accept", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> accept(@RequestBody KkoAlimtalkAcceptReqDTO reqDTO) {

        EnsResponseVO responseVO = kkoAlimtalkService.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 = "{\"sendMastId\": 1}")
            })
    })
    @Operation(summary = "제작")
//    @PutMapping(value = "/kko/alimtalk/make", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/kko/alimtalk/make", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> make(@RequestBody Map<String, Long> mParam) {

        EnsResponseVO responseVO = kkoAlimtalkService.make(mParam.get("sendMastId"));

        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 = "{\"sendMastId\": 1}")
            })
    })
    @Operation(summary = "제작(템플릿메시지)")
//    @PutMapping(value = "/kko/alimtalk/make/tmpltmsg", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/kko/alimtalk/make/tmpltmsg", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> makeTmpltMsg(@RequestBody Map<String, Long> mParam) {

        EnsResponseVO responseVO = kkoAlimtalkService.makeTmpltMsg(mParam.get("sendMastId"));

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


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

        EnsResponseVO responseVO = kkoAlimtalkService.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 = "{\"sendMastId\": 1}")
            })
    })
    @Operation(summary = "(대량)전송요청")
    @PostMapping(value = "/kko/alimtalk/send/bulk", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> sendBulk(@RequestBody Map<String, Long> mParam) {
        EnsResponseVO responseVO = kkoAlimtalkService.sendBulk(mParam.get("sendMastId"));

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

    @Operation(summary = "(대량)전송요청 일괄")
    @PostMapping(value = "/kko/alimtalk/send/bulk/all", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> sendBulkAll() {
        EnsResponseVO responseVO = kkoAlimtalkService.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 = "{\"sendMastId\": 1, \"btToken\": \"eyJhbGciOiJIUzI1NiJ9.eyJic2lkIjoia290aSIsImV4cCI6MTY0NDQwMjI3MywiaWF0IjoxNjQ0MzE1ODczLCJpcEFkZHIiOiIyMTEuMTE5LjEyNC40MiJ9.7gAQF0FJrVAsRg2umAULa4R7UZFCjnk49Vyo02mYYlU\"}")
            })
    })
    @Operation(summary = "(대량)문서상태 갱신")
//    @PutMapping(value = "/kko/alimtalk/stat/bulk", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/kko/alimtalk/stat/bulk", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> statBulk(@RequestBody Map<String, Object> mParam) {

        EnsResponseVO responseVO = kkoAlimtalkService.statBulk((String) mParam.get("btToken"), Long.valueOf((Integer) mParam.get("sendMastId")));

        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 = "{\"sendMastId\": 1}")
            })
    })
    @Operation(summary = "전송결과 가져오기")
    @PostMapping(value = "/kko/alimtalk/send/result/provide", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> sendResultProvide(@RequestBody Map<String, Long> mParam) {

        EnsResponseVO responseVO = kkoAlimtalkService.sendResultProvide(mParam.get("sendMastId"));


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