package com.its.op.service.its.road;

import com.its.op.dao.repository.its.road.TbRoadVrtxArrRepository;
import com.its.op.dto.its.road.TbRoadVrtxArrDto;
import com.its.op.entity.its.road.TbRoadVrtxArr;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@Service
public class TbRoadVrtxArrService {

    private final TbRoadVrtxArrRepository repo;

    // 전체 데이터 조회
    @Transactional(readOnly = true)
    public List<TbRoadVrtxArrDto> findAll() {
        List<TbRoadVrtxArrDto> result = new ArrayList<>();
        List<TbRoadVrtxArr> data = this.repo.findAll();
        for (TbRoadVrtxArr entity : data) {
            result.add(entity.toDto());
        }
        return result;
    }

    /**
     * 레벨에 따른 버텍스 정보 조회
     * @param levl
     * @return
     */
    public List<TbRoadVrtxArrDto> findAllByLevl(Integer levl) {
        List<TbRoadVrtxArrDto> result = new ArrayList<>();
        List<TbRoadVrtxArr> data = this.repo.findAllByLevl(levl);
        data.forEach(obj -> {
            result.add(obj.toDto());
        });
        return result;
    }
}
