package com.its.op.service.its.weather;

import com.its.op.dto.its.weather.TbVilgFrcsPnstDto;
import com.its.op.dto.its.weather.TbVilgFrcsZoneDto;
import com.its.op.entity.its.weather.TbVilgFrcsPnst;
import com.its.op.entity.its.weather.TbVilgFrcsZone;
import com.its.op.dao.repository.its.weather.TbVilgFrcsPnstRepository;
import com.its.op.dao.repository.its.weather.TbVilgFrcsZoneRepository;
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 TbVilgFrcsZoneService {

    private final TbVilgFrcsZoneRepository repo;
    private final TbVilgFrcsPnstRepository frcsRepo;

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

    /**
     * 동네 예보 구역 전체 조회
     * @return
     */
    @Transactional(readOnly = true)
    public List<TbVilgFrcsZoneDto> findAllList() {
        List<TbVilgFrcsZoneDto> result = new ArrayList<>();
        List<TbVilgFrcsZone> data = this.repo.findAll();
        data.forEach(obj -> {
            result.add(obj.toDto());
        });
        return result;
    }

    /**
     * 동네 예보 조회
     * @return
     */
    @Transactional(readOnly = true)
    public List<TbVilgFrcsPnstDto> findAllRealtimeStatus() {
        List<TbVilgFrcsPnstDto> result = new ArrayList<>();
        List<TbVilgFrcsPnst> data = this.frcsRepo.findAllList();
        data.forEach(obj -> {
            result.add(obj.toDto());
        });
        return result;
    }

}
