package com.kamco.cd.kamcoback.scene;

import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
import com.kamco.cd.kamcoback.common.enums.CommonUseStatus;
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
import com.kamco.cd.kamcoback.config.api.ApiResponseDto.ApiResponseCode;
import com.kamco.cd.kamcoback.config.api.ApiResponseDto.ResponseObj;
import com.kamco.cd.kamcoback.scene.dto.MapInkxMngDto;
import com.kamco.cd.kamcoback.scene.service.MapInkxMngService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "도엽 관리", description = "도엽 관리 API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/scene")
public class MapInkxMngApiController {

  private final MapInkxMngService mapInkxMngService;

  @Operation(summary = "목록 조회", description = "도엽 목록 조회")
  @ApiResponses(
      value = {
        @ApiResponse(
            responseCode = "200",
            description = "조회 성공",
            content =
                @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = CommonCodeDto.Basic.class))),
        @ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
        @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
      })
  @GetMapping
  public ApiResponseDto<Page<MapInkxMngDto.MapList>> findMapInkxMngList(
      @RequestParam(defaultValue = "0") int page,
      @RequestParam(defaultValue = "20") int size,
      @RequestParam(required = false) CommonUseStatus useInference,
      @RequestParam(required = false) String searchVal) {
    MapInkxMngDto.searchReq searchReq = new MapInkxMngDto.searchReq(page, size, "");
    return ApiResponseDto.ok(
        mapInkxMngService.findMapInkxMngList(searchReq, useInference, searchVal));
  }

  @Operation(summary = "저장", description = "도엽정보를 저장 합니다.")
  @ApiResponses(
      value = {
        @ApiResponse(
            responseCode = "201",
            description = "도엽정보 저장 성공",
            content =
                @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = ApiResponseDto.ResponseObj.class))),
        @ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
        @ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
        @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
      })
  @PostMapping
  public ApiResponseDto<ApiResponseDto.ResponseObj> saveMapInkx5k(
      @io.swagger.v3.oas.annotations.parameters.RequestBody(
              description = "도엽정보 생성 요청 정보",
              required = true,
              content =
                  @Content(
                      mediaType = "application/json",
                      schema = @Schema(implementation = MapInkxMngDto.AddMapReq.class)))
          @RequestBody
          @Valid
          MapInkxMngDto.AddMapReq addReq) {
    return ApiResponseDto.okObject(mapInkxMngService.saveMapInkx5k(addReq));
  }

  @Operation(summary = "추론제외 업데이트", description = "추론제외 업데이트 합니다.")
  @ApiResponses(
      value = {
        @ApiResponse(
            responseCode = "201",
            description = "추론제외 업데이트 성공",
            content =
                @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = ApiResponseDto.ResponseObj.class))),
        @ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
        @ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
        @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
      })
  @PutMapping("/use-inference")
  public ApiResponseDto<ApiResponseDto.ResponseObj> updateUseInference(
      @io.swagger.v3.oas.annotations.parameters.RequestBody(
              description = "추론제외 업데이트 정보",
              required = true,
              content =
                  @Content(
                      mediaType = "application/json",
                      schema = @Schema(implementation = MapInkxMngDto.UseInferReq.class)))
          @RequestBody
          @Valid
          MapInkxMngDto.UseInferReq useInferReq) {
    mapInkxMngService.updateUseInference(useInferReq);
    return ApiResponseDto.okObject(new ResponseObj(ApiResponseCode.OK, ""));
  }
}
