package com.its.op.service.its.vms;

import com.its.op.dao.repository.its.vms.TbVmsCtrlHsRepository;
import com.its.op.dto.its.vms.TbVmsCtrlHsDto;
import com.its.op.entity.its.vms.TbVmsCtrlHs;
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 TbVmsCtrlHsService {

    private final TbVmsCtrlHsRepository repo;

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

    public List<TbVmsCtrlHsDto> findAllByDateRange(String fromDt, String toDt, List<Long> ids) {

        List<TbVmsCtrlHsDto> result = new ArrayList<>();
        List<TbVmsCtrlHs> data = this.repo.findAllByDateRange(fromDt, toDt, ids);
        if (data != null) {
            data.forEach(obj -> {
                result.add(obj.toDto());
            });
        }
        return result;
    }
}
