package com.caliverse.admin.logs.logservice;



import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

import com.caliverse.admin.logs.Indicatordomain.StartEndTime;

public class LogServiceHelper {
    

    public static StartEndTime getCurrentLogSearchEndTime(int minusDay){

        StartEndTime startEndTime = new StartEndTime();
        ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));

        ZonedDateTime end = now.toLocalDate().atStartOfDay(ZoneId.of("UTC"));
        String endTimeStr = end.format(DateTimeFormatter.ISO_INSTANT);
        startEndTime.setEndTime(endTimeStr);
        
        // 전 날 00시 UTC 시간 설정
        ZonedDateTime start = end.minusDays(minusDay);
        String startTimeStr = start.format(DateTimeFormatter.ISO_INSTANT);
        startEndTime.setStartTime(startTimeStr);
        //System.out.println("전 날의 00시 UTC: " + startTimeStr);
        //System.out.println("오늘 날짜의 00시 UTC: " + endTimeStr);

        return startEndTime;
    }

    public static StartEndTime getCurrentLogSearchEndTime(LocalDate endDate, int minusDay) {
        StartEndTime startEndTime = new StartEndTime();

        // LocalDate를 UTC ZonedDateTime으로 변환
        ZonedDateTime end = endDate.atStartOfDay(ZoneId.of("UTC"));
        startEndTime.setEndTime(end.format(DateTimeFormatter.ISO_INSTANT));

        // startTime 계산
        ZonedDateTime start = end.minusDays(minusDay);
        startEndTime.setStartTime(start.format(DateTimeFormatter.ISO_INSTANT));

        return startEndTime;
    }
    
}
