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

import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.Dashboard;
import com.kamco.cd.kamcoback.postgres.repository.Inference.InferenceResultRepository;
import jakarta.persistence.EntityNotFoundException;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class InferenceResultCoreService {

  private final InferenceResultRepository inferenceResultRepository;

  /**
   * 추론관리 > 분석결과 목록 조회
   *
   * @param searchReq
   * @return
   */
  public Page<InferenceResultDto.AnalResList> getInferenceResultList(
      InferenceResultDto.SearchReq searchReq) {
    return inferenceResultRepository.getInferenceResultList(searchReq);
  }

  /**
   * 분석결과 요약정보
   *
   * @param id
   * @return
   */
  public InferenceResultDto.AnalResSummary getInferenceResultSummary(Long id) {
    InferenceResultDto.AnalResSummary summary =
        inferenceResultRepository
            .getInferenceResultSummary(id)
            .orElseThrow(() -> new EntityNotFoundException("요약정보를 찾을 수 없습니다. " + id));
    return summary;
  }

  /**
   * 분석결과 상세 class name별 탐지 개수
   *
   * @param id
   * @return
   */
  public List<Dashboard> getDashboard(Long id) {
    return inferenceResultRepository.getDashboard(id);
  }

  /**
   * 분석결과 상세 목록
   *
   * @param searchGeoReq
   * @return
   */
  public Page<InferenceResultDto.Geom> getInferenceResultGeomList(
      Long id, InferenceResultDto.SearchGeoReq searchGeoReq) {
    return inferenceResultRepository.getInferenceGeomList(id, searchGeoReq);
  }

  /**
   * 추론된 5000:1 도엽 목록
   *
   * @param id
   * @return
   */
  public List<Long> getSheets(Long id) {
    return inferenceResultRepository.getSheets(id);
  }
}
