package com.kamco.cd.kamcoback.zoo.service;

import com.kamco.cd.kamcoback.postgres.core.AnimalCoreService;
import com.kamco.cd.kamcoback.zoo.dto.AnimalDto;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
public class AnimalService {

  private final AnimalCoreService zooCoreService;

  // 동물의 UUID로 id조회
  public Long getAnimalByUuid(String uuid) {
    return zooCoreService.getDataByUuid(uuid).getId();
  }

  /**
   * 동물 생성
   *
   * @param req 동물 생성 요청
   * @return 생성된 동물 정보
   */
  @Transactional
  public AnimalDto.Basic createAnimal(AnimalDto.AddReq req) {
    return zooCoreService.create(req);
  }

  /**
   * 동물 삭제 (논리 삭제)
   *
   * @param id 동물 ID
   */
  @Transactional
  public void deleteAnimal(Long id) {
    zooCoreService.remove(id);
  }

  /**
   * 동물 단건 조회
   *
   * @param id 동물 ID
   * @return 동물 정보
   */
  public AnimalDto.Basic getAnimal(Long id) {
    return zooCoreService.getOneById(id);
  }

  /**
   * 동물 검색 (페이징)
   *
   * @param searchReq 검색 조건
   * @return 페이징 처리된 동물 목록
   */
  public Page<AnimalDto.Basic> search(AnimalDto.SearchReq searchReq) {
    return zooCoreService.search(searchReq);
  }
}
