package com.kamco.cd.kamcoback.mapsheet;

import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
import com.kamco.cd.kamcoback.code.service.CommonCodeService;
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.FilesDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.FoldersDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.SrchFilesDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.SrchFoldersDto;
import com.kamco.cd.kamcoback.mapsheet.service.MapSheetMngFileCheckerService;
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 lombok.RequiredArgsConstructor;
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;

@Tag(name = "영상 관리", description = "영상 관리 API")
@RestController
@RequiredArgsConstructor
@RequestMapping({"/api/mapsheet"})
public class MapSheetMngFileCheckerApiController {

  private final CommonCodeService commonCodeService;
  private final MapSheetMngFileCheckerService mapSheetMngFileCheckerService;

  @Operation(summary = "폴더 조회", description = "폴더 조회 (ROOT:/app/original-images 이하로 경로입력)")
  @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)
      })
  @PostMapping("/folder-list")
  public ApiResponseDto<FoldersDto> getDir(@RequestBody SrchFoldersDto srchDto) {

    return ApiResponseDto.createOK(mapSheetMngFileCheckerService.getFolderAll(srchDto));
  }

  @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)
      })
  @PostMapping("/file-list")
  public ApiResponseDto<FilesDto> getFiles(@RequestBody SrchFilesDto srchDto) {

    return ApiResponseDto.createOK(mapSheetMngFileCheckerService.getFilesAll(srchDto));
  }

  /*
  @Operation(summary = "파일 업로드", description = "파일 업로드 및 TIF 검증")
  @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
  public ApiResponseDto<String> uploadFile(
      @RequestPart("file") MultipartFile file,
      @RequestParam("targetPath") String targetPath,
      @RequestParam(value = "overwrite", required = false, defaultValue = "false")
          boolean overwrite,
      @RequestParam(value = "hstUid", required = false) Long hstUid) {
    return ApiResponseDto.createOK(
        mapSheetMngFileCheckerService.uploadFile(file, targetPath, overwrite, hstUid));
  }

   */

  /*
  @Operation(summary = "파일 삭제", description = "중복 파일 등 파일 삭제")
  @PostMapping("/delete")
  public ApiResponseDto<Boolean> deleteFile(@RequestBody SrchFoldersDto dto) {
    return ApiResponseDto.createOK(mapSheetMngFileCheckerService.deleteFile(dto.getDirPath()));
  }

  @Operation(summary = "중복 파일 삭제", description = "중복 데이터 발견 시 기존 데이터를 삭제")
  @PostMapping(value = "/delete-file")
  public ApiResponseDto<String> deleteDuplicateFile(
      @RequestParam("filePath") String filePath, @RequestParam("fileName") String fileName) {
    return ApiResponseDto.createOK(
        mapSheetMngFileCheckerService.deleteDuplicate(filePath, fileName));
  }

   */

  /*
  @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)
      })
  @PostMapping("/file-all-list")
  public ApiResponseDto<FilesDto> getAllFiles(@RequestBody SrchFilesDepthDto srchDto) {

    return ApiResponseDto.createOK(mapSheetMngFileCheckerService.getFilesDepthAll(srchDto));
  }

  @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)
      })
  @PostMapping("/sync-process")
  public ApiResponseDto<ImageryDto.SyncReturn> syncProcess(
      @RequestBody @Valid ImageryDto.searchReq searchReq) {
    return ApiResponseDto.ok(mapSheetMngFileCheckerService.syncProcess(searchReq));
  }


   */
}
