package kr.xit.core.biz.batch.web;

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.core.biz.batch.model.BatchCmmDTO.BatchCmmRequest;
import kr.xit.core.biz.batch.service.IBatchCmmService;
import kr.xit.core.model.ApiResponseDTO;
import kr.xit.core.model.IApiResponse;
import lombok.RequiredArgsConstructor;
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;

/**
 * <pre>
 * description :
 *
 * packageName : kr.xit.core.biz.batch.web
 * fileName    : BatchCmmController
 * author      : limju
 * date        : 2023-10-19
 * ======================================================================
 * 변경일         변경자        변경 내용
 * ----------------------------------------------------------------------
 * 2023-10-19    limju       최초 생성
 *
 * </pre>
 */
@Tag(name = "BatchCmmController", description = "배치 관리")
@RequiredArgsConstructor
@RestController
@RequestMapping("/batch/cmm/v1")
public class BatchCmmController {
    private static final String PARAM1 = """
                        {
                          "signguCode": "88328",
                          "ffnlgCode": "11",
                          "profile": "local",
                          "instanceId": "EnsCctvAcceptJob"
                        }
                    """;
    private static final String PARAM2 = """
                        {
                          "signguCode": "88316",
                          "ffnlgCode": "11",
                          "profile": "local",
                          "instanceId": "EnsCctvAcceptJob"
                        }
                    """;

    private final IBatchCmmService service;

    @Operation(summary = "배치 목록 조회", description = "배치 목록 조회")
    @PostMapping(value = "/findBatchLocks", produces = MediaType.APPLICATION_JSON_VALUE)
    public IApiResponse findBatchLocks(){
        return ApiResponseDTO.success(service.findBatchLocks());
    }

    @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
        @Content(
            mediaType = "application/json",
            examples = {
                @ExampleObject(
                    name = "교통시설운영처",
                    value = PARAM1),
                @ExampleObject(
                    name = "승화원",
                    value = PARAM2)
            })
    })
    @Operation(summary = "배치 실행", description = "배치 실행")
    @PostMapping(value = "/execBatch", produces = MediaType.APPLICATION_JSON_VALUE)
    public IApiResponse execBatch(@RequestBody final BatchCmmRequest reqDTO){
        return ApiResponseDTO.success(service.execBatch(reqDTO));
        //return null;
    }
}
