package kr.xit.biz.ens.web;

import org.springframework.http.MediaType;
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.RestController;

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 kr.xit.biz.ens.model.EnsDTO;
import kr.xit.biz.ens.service.IEnsBatchAcceptService;
import kr.xit.biz.ens.service.IEnsBatchCloseService;
import kr.xit.biz.ens.service.IEnsBatchStatusService;
import kr.xit.core.model.ApiResponseDTO;
import kr.xit.core.model.IApiResponse;
import lombok.RequiredArgsConstructor;

/**
 * <pre>
 * description : 모바일 전자고지 배치
 *
 * packageName : kr.xit.biz.ens.web
 * fileName    : EnsBatchController
 * author      : limju
 * date        : 2023-08-31
 * ======================================================================
 * 변경일         변경자        변경 내용
 * ----------------------------------------------------------------------
 * 2023-08-31    limju       최초 생성
 *
 * </pre>
 */
@Tag(name = "EnsBatchController", description = "전자고지 배치 테스트")
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/batch/ens/v1")
public class EnsBatchController {
    private final IEnsBatchAcceptService acceptService;
    private final IEnsBatchStatusService statusService;
    private final IEnsBatchCloseService closeService;

    private static final String CAN_1 = """
                        {
                          "signguCode": "44131",
                          "ffnlgCode": "11",
                          "profile": "local"
                        }
                    """;
    private static final String CAN_2 = """
                        {
                          "signguCode": "44133",
                          "ffnlgCode": "11",
                          "profile": "local"
                        }
                    """;

    private static final String CCN = """
                        {
                          "signguCode": "51110",
                          "ffnlgCode": "11",
                          "profile": "local"
                        }
                    """;

    @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
        @Content(
            mediaType = "application/json",
            examples = {
                @ExampleObject(
                    name = "춘천",
                    value = CCN),
                @ExampleObject(
                    name = "천안시 동남구청",
                    value = CAN_1),
                @ExampleObject(
                    name = "천안시 서북구청",
                    value = CAN_2)
            })
    })
    @Operation(summary = "통합문서 접수", description = "통합문서 접수")
    @PostMapping(value = "/accept", produces = MediaType.APPLICATION_JSON_VALUE)
    public IApiResponse accept(@RequestBody final EnsDTO.BatchEnsRequest reqDTO) {
        acceptService.accept(reqDTO);
        return ApiResponseDTO.success();
    }

    @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
        @Content(
            mediaType = "application/json",
            examples = {
                @ExampleObject(
                    name = "춘천",
                    value = CCN),
                @ExampleObject(
                    name = "천안시 동남구청",
                    value = CAN_1),
                @ExampleObject(
                    name = "천안시 서북구청",
                    value = CAN_2)
            })
    })
    @Operation(summary = "통합문서 발송 데이타 종료", description = "통합문서 발송 데이타 종료")
    @PostMapping(value = "/close", produces = MediaType.APPLICATION_JSON_VALUE)
    public IApiResponse close(@RequestBody final EnsDTO.BatchEnsRequest reqDTO){
        closeService.close(reqDTO);
        return ApiResponseDTO.success();
    }

    @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
        @Content(
            mediaType = "application/json",
            examples = {
                @ExampleObject(
                    name = "춘천",
                    value = CCN),
                @ExampleObject(
                    name = "천안시 동남구청",
                    value = CAN_1),
                @ExampleObject(
                    name = "천안시 서북구청",
                    value = CAN_2)
            })
    })
    @Operation(summary = "통합문서(bulk) 상태 조회", description = "통합문서 상태 조회")
    @PostMapping(value = "/statusBulks", produces = MediaType.APPLICATION_JSON_VALUE)
    public IApiResponse statusBulks(@RequestBody final EnsDTO.BatchEnsRequest reqDTO){
        statusService.statusBulks(reqDTO);
        return ApiResponseDTO.success();
    }
}
