package com.kamco.cd.training.postgres.core;

import com.kamco.cd.training.postgres.repository.train.ModelTestMetricsJobRepository;
import com.kamco.cd.training.train.dto.ModelTrainMetricsDto.ModelMetricJsonDto;
import com.kamco.cd.training.train.dto.ModelTrainMetricsDto.ModelTestFileName;
import com.kamco.cd.training.train.dto.ModelTrainMetricsDto.ResponsePathDto;
import java.time.ZonedDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class ModelTestMetricsJobCoreService {

  private final ModelTestMetricsJobRepository modelTestMetricsJobRepository;

  @Transactional
  public void updateModelMetricsTrainSaveYn(Long modelId, String stepNo) {
    modelTestMetricsJobRepository.updateModelMetricsTrainSaveYn(modelId, stepNo);
  }

  // Test 로직 시작
  public List<ResponsePathDto> getTestMetricSaveNotYetModelIds() {
    return modelTestMetricsJobRepository.getTestMetricSaveNotYetModelIds();
  }

  public void insertModelMetricsTest(List<Object[]> batchArgs) {
    modelTestMetricsJobRepository.insertModelMetricsTest(batchArgs);
  }

  public ModelMetricJsonDto getTestMetricPackingInfo(Long modelId) {
    return modelTestMetricsJobRepository.getTestMetricPackingInfo(modelId);
  }

  public ModelTestFileName findModelTestFileNames(Long modelId) {
    return modelTestMetricsJobRepository.findModelTestFileNames(modelId);
  }

  @Transactional
  public void updatePackingStart(Long modelId, ZonedDateTime now) {
    modelTestMetricsJobRepository.updatePackingStart(modelId, now);
  }

  @Transactional
  public void updatePackingEnd(Long modelId, ZonedDateTime now, String failSuccState) {
    modelTestMetricsJobRepository.updatePackingEnd(modelId, now, failSuccState);
  }
}
