package com.its.api.its.service.vds;

import com.its.api.its.model.dto.vds.TbVdsDtct15mStatDto;
import com.its.api.its.model.dto.vds.TbVdsDtctDdStatDto;
import com.its.api.its.model.dto.vds.TbVdsDtctHhStatDto;
import com.its.api.its.model.dto.vds.TbVdsDtctMnStatDto;
import com.its.api.its.model.entity.vds.TbVdsDtct15mStat;
import com.its.api.its.model.entity.vds.TbVdsDtctDdStat;
import com.its.api.its.model.entity.vds.TbVdsDtctHhStat;
import com.its.api.its.model.entity.vds.TbVdsDtctMnStat;
import com.its.api.its.repository.vds.TbVdsDtct15mStatRepository;
import com.its.api.its.repository.vds.TbVdsDtctDdStatRepository;
import com.its.api.its.repository.vds.TbVdsDtctHhStatRepository;
import com.its.api.its.repository.vds.TbVdsDtctMnStatRepository;
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 TbVdsDtct15mStatRepository stat15MRepo;
    private final TbVdsDtctHhStatRepository statHHRepo;
    private final TbVdsDtctDdStatRepository statDDRepo;
    private final TbVdsDtctMnStatRepository statMNRepo;

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

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

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

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

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

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

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