package com.its.op.service.its.link;

import com.its.op.dao.repository.its.link.TbLinkVrtxArrRepository;
import com.its.op.dto.its.link.TbLinkVrtxArrDto;
import com.its.op.entity.its.link.TbLinkVrtxArr;
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 TbLinkVrtxArrService {

    private final TbLinkVrtxArrRepository repo;

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

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