package com.kamco.cd.kamcoback.model;

import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
import com.kamco.cd.kamcoback.model.dto.ModelMgmtDto;
import com.kamco.cd.kamcoback.model.service.ModelMgmtService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.transaction.Transactional;
import java.time.LocalDate;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
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")
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/model")
@Transactional
public class ModelMgmtApiController {

  private final ModelMgmtService modelMgmtService;

  @Operation(summary = "모델관리 목록")
  @GetMapping
  public ApiResponseDto<Page<ModelMgmtDto.ModelList>> findModelMgmtList(
      @RequestParam(required = false) LocalDate startDate,
      @RequestParam(required = false) LocalDate endDate,
      @RequestParam(required = false, defaultValue = "createCompleteDttm") String sortColumn,
      @RequestParam(required = false) String modelType,
      @RequestParam(required = false) String searchVal,
      @RequestParam(defaultValue = "0") int page,
      @RequestParam(defaultValue = "20") int size) {
    ModelMgmtDto.searchReq searchReq = new ModelMgmtDto.searchReq(page, size, sortColumn + ",desc");

    Page<ModelMgmtDto.ModelList> result =
        modelMgmtService.findModelMgmtList(searchReq, startDate, endDate, modelType, searchVal);

    return ApiResponseDto.ok(result);
  }
}
