package com.utic.center.utic.stat.server.service;

import com.utic.center.common.annotation.ProcessingElapsed;
import com.utic.center.common.service.AbstractProcessService;
import com.utic.center.common.utils.TimeUtils;
import com.utic.center.utic.stat.server.dao.repository.UticStat04MinEtlpRepository;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Slf4j
@Getter
@RequiredArgsConstructor
@Service
public class UticStat04MinEtlpService implements AbstractProcessService {

    private final UticStat04MinEtlpRepository etlpRepo;

    private String past10Min;

    private void initialize() {
        LocalDateTime now = LocalDateTime.now();
        int year = now.getYear();
        int month = now.getMonthValue();
        int day = now.getDayOfMonth();
        int hour = now.getHour();
        int minute = now.getMinute();
        String prcsTime = String.format("%04d%02d%02d%02d%02d00", year, month, day, hour, minute);
        this.past10Min = TimeUtils.addMinutes(prcsTime, -10);
    }

    @ProcessingElapsed(type="ETLP", name="교통정보 이관 작업", starting = false)
    @Override
    public boolean processing() {

        initialize();

        // RCV_LINK_TRAFFIC 교통정보 입력
        this.etlpRepo.insertRcvLinkTraffic(this.past10Min);

        // INCIDENT_CENTER 돌발정보 수집(연계하지 않음, 2025-09-08)
//        this.etlpRepo.mergeIncidentCenter(this.past10Min);
        return true;
    }

}
