package com.kamco.cd.training.model;

import com.kamco.cd.training.config.api.ApiResponseDto;
import com.kamco.cd.training.model.dto.ModelTrainDetailDto;
import com.kamco.cd.training.model.dto.ModelTrainDetailDto.MappingDataset;
import com.kamco.cd.training.model.dto.ModelTrainDetailDto.TransferDetailDto;
import com.kamco.cd.training.model.dto.ModelTrainMngDto.Basic;
import com.kamco.cd.training.model.service.ModelTrainDetailService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
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 java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@Tag(name = "모델학습 관리", description = "어드민 홈 > 모델학습관리 > 모델관리 > 목록")
@RequestMapping("/api/models")
public class ModelTrainDetailApiController {
  private final ModelTrainDetailService modelTrainDetailService;

  @Operation(summary = "모델학습관리> 모델관리 > 상세정보탭 > 학습 진행정보", description = "학습 진행정보, 모델학습 정보 API")
  @ApiResponses(
      value = {
        @ApiResponse(
            responseCode = "200",
            description = "조회 성공",
            content =
                @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = Basic.class))),
        @ApiResponse(responseCode = "404", description = "데이터셋을 찾을 수 없음", content = @Content),
        @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
      })
  @GetMapping("/detail/{uuid}")
  public ApiResponseDto<Basic> findByModelByUUID(
      @Parameter(description = "모델학습 uuid", example = "7fbdff54-ea87-4b02-90d1-955fa2a3457e")
          @PathVariable
          UUID uuid) {
    return ApiResponseDto.ok(modelTrainDetailService.findByModelByUUID(uuid));
  }

  @Operation(summary = "모델학습관리> 모델관리 > 상세정보탭 > 요약정보", description = "상세정보 탭 요약정보 API")
  @ApiResponses(
      value = {
        @ApiResponse(
            responseCode = "200",
            description = "조회 성공",
            content =
                @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = ModelTrainDetailDto.DetailSummary.class))),
        @ApiResponse(responseCode = "404", description = "데이터셋을 찾을 수 없음", content = @Content),
        @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
      })
  @GetMapping("/summary/{uuid}")
  public ApiResponseDto<ModelTrainDetailDto.DetailSummary> getModelDetailSummary(
      @Parameter(description = "모델학습 uuid", example = "7fbdff54-ea87-4b02-90d1-955fa2a3457e")
          @PathVariable
          UUID uuid) {
    return ApiResponseDto.ok(modelTrainDetailService.getModelDetailSummary(uuid));
  }

  @Operation(summary = "모델학습관리> 모델관리 > 상세정보탭 > 하이퍼파라미터 요약 정보", description = "하이퍼파라미터 요약 정보 API")
  @ApiResponses(
      value = {
        @ApiResponse(
            responseCode = "200",
            description = "조회 성공",
            content =
                @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = ModelTrainDetailDto.HyperSummary.class))),
        @ApiResponse(responseCode = "404", description = "데이터셋을 찾을 수 없음", content = @Content),
        @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
      })
  @GetMapping("/hyper-summary/{uuid}")
  public ApiResponseDto<ModelTrainDetailDto.HyperSummary> getByModelHyperParamSummary(
      @Parameter(description = "모델학습 uuid", example = "7fbdff54-ea87-4b02-90d1-955fa2a3457e")
          @PathVariable
          UUID uuid) {
    return ApiResponseDto.ok(modelTrainDetailService.getByModelHyperParamSummary(uuid));
  }

  @Operation(summary = "모델학습관리> 모델관리 > 상세정보탭 > 데이터셋 정보", description = "모델학습 상세 데이터셋 정보 API")
  @ApiResponses({
    @ApiResponse(
        responseCode = "200",
        description = "조회 성공",
        content =
            @Content(
                mediaType = "application/json",
                array = @ArraySchema(schema = @Schema(implementation = MappingDataset.class)))),
    @ApiResponse(responseCode = "404", description = "데이터셋을 찾을 수 없음"),
    @ApiResponse(responseCode = "500", description = "서버 오류")
  })
  @GetMapping("/mapp-dataset/{uuid}")
  public ApiResponseDto<List<MappingDataset>> getByModelMappingDataset(
      @Parameter(description = "모델학습 uuid", example = "7fbdff54-ea87-4b02-90d1-955fa2a3457e")
          @PathVariable
          UUID uuid) {
    return ApiResponseDto.ok(modelTrainDetailService.getByModelMappingDataset(uuid));
  }

  @Operation(summary = "모델관리 > 전이 학습 실행설정 > 모델선택", description = "모델선택 정보 API")
  @ApiResponses(
      value = {
        @ApiResponse(
            responseCode = "200",
            description = "조회 성공",
            content =
                @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = TransferDetailDto.class))),
        @ApiResponse(responseCode = "404", description = "데이터셋을 찾을 수 없음", content = @Content),
        @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
      })
  @GetMapping("/transfer/detail/{uuid}")
  public ApiResponseDto<TransferDetailDto> getTransferDetail(
      @Parameter(description = "모델 uuid", example = "7fbdff54-ea87-4b02-90d1-955fa2a3457e")
          @PathVariable
          UUID uuid) {
    return ApiResponseDto.ok(modelTrainDetailService.getTransferDetail(uuid));
  }
}
