package com.its.op.service.its.vds;

import com.its.op.dto.its.vds.TbVdsDtctStat15mDto;
import com.its.op.dto.its.vds.TbVdsDtctStatDdDto;
import com.its.op.dto.its.vds.TbVdsDtctStatHhDto;
import com.its.op.dto.its.vds.TbVdsDtctStatMnDto;
import com.its.op.entity.its.vds.TbVdsDtctStat15m;
import com.its.op.entity.its.vds.TbVdsDtctStatDd;
import com.its.op.entity.its.vds.TbVdsDtctStatHh;
import com.its.op.entity.its.vds.TbVdsDtctStatMn;
import com.its.op.dao.repository.its.vds.TbVdsDtctStat15mRepository;
import com.its.op.dao.repository.its.vds.TbVdsDtctStatDdRepository;
import com.its.op.dao.repository.its.vds.TbVdsDtctStatHhRepository;
import com.its.op.dao.repository.its.vds.TbVdsDtctStatMnRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

@Slf4j
@RequiredArgsConstructor
@Service
public class VdsDtctTrafStatService {

    private final TbVdsDtctStat15mRepository stat15MRepo;
    private final TbVdsDtctStatHhRepository statHHRepo;
    private final TbVdsDtctStatDdRepository statDDRepo;
    private final TbVdsDtctStatMnRepository statMNRepo;

    public List<TbVdsDtctStat15mDto> findAll15M(String FROM_DT, String TO_DT, List<Long> idList) {

        List<TbVdsDtctStat15mDto> result = new ArrayList<>();
        List<TbVdsDtctStat15m> data = this.stat15MRepo.findAllByDateRange(FROM_DT, TO_DT, idList);
        if (data != null) {
            data.forEach(obj -> {
                result.add(obj.toDto());
            });
        }
        return result;
    }

    public List<TbVdsDtctStatHhDto> findAllHH(String FROM_DT, String TO_DT, List<Long> idList) {
        List<TbVdsDtctStatHhDto> result = new ArrayList<>();
        List<TbVdsDtctStatHh> data = this.statHHRepo.findAllByDateRange(FROM_DT, TO_DT, idList);
        if (data != null) {
            data.forEach(obj -> {
                result.add(obj.toDto());
            });
        }
        return result;
    }

    public List<TbVdsDtctStatDdDto> findAllDD(String FROM_DT, String TO_DT, List<Long> idList) {

        List<TbVdsDtctStatDdDto> result = new ArrayList<>();
        List<TbVdsDtctStatDd> data = this.statDDRepo.findAllByDateRange(FROM_DT, TO_DT, idList);
        if (data != null) {
            data.forEach(obj -> {
                result.add(obj.toDto());
            });
        }
        return result;
    }

    public List<TbVdsDtctStatMnDto> findAllMN(String FROM_DT, String TO_DT, List<Long> idList) {

        List<TbVdsDtctStatMnDto> result = new ArrayList<>();
        List<TbVdsDtctStatMn> data = this.statMNRepo.findAllByDateRange(FROM_DT, TO_DT, idList);
        if (data != null) {
            data.forEach(obj -> {
                result.add(obj.toDto());
            });
        }
        return result;
    }
}
