package com.caliverse.admin.scheduler;

import com.caliverse.admin.dynamodb.service.DynamodbService;
import com.caliverse.admin.global.common.constants.AdminConstants;
import com.caliverse.admin.logs.Indicatordomain.StartEndTime;
import com.caliverse.admin.logs.logservice.LogServiceHelper;
import com.caliverse.admin.logs.logservice.indicators.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

@Component
@Order(1)
@RequiredArgsConstructor
@Slf4j
public class OneTimeSchedule implements CommandLineRunner {
    @Autowired private IndicatorsDauService dauService;
    @Autowired private IndicatorsWauService wauService;
    @Autowired private IndicatorsMauService mauService;
    @Autowired private IndicatorsMcuService mcuService;
    @Autowired private IndicatorsNruService nruService;
    @Autowired private IndicatorsPlayTimeService playTimeService;
    @Autowired private IndicatorsDglcService dglcService;
    @Autowired private IndicatorsDBCapacityService capacityService;
    @Autowired private IndicatorsUgqCreateService ugqCreateService;
    @Autowired private IndicatorsMetaverseServerService metaverseServerService;
    @Autowired private DynamodbService dynamodbService;

    @Override
    public void run(String... args) throws Exception {
        try{
            log.info("Starting OneTimeSchedule");
//            dynamodbService.saveUserMoney();  //유저별 재화 데이터 저장

//            LocalDate startDate = LocalDate.of(2024, 11, 8);
////            LocalDate currentDate = LocalDate.of(2024, 9, 10);
//            LocalDate currentDate = LocalDate.now();
//
//            for (LocalDate date = startDate; !date.isAfter(currentDate); date = date.plusDays(1)) {
//                StartEndTime dayStartEndTime = LogServiceHelper.getCurrentLogSearchEndTime(date, AdminConstants.STAT_DAY_NUM);
//                StartEndTime weekStartEndTime = LogServiceHelper.getCurrentLogSearchEndTime(date, AdminConstants.STAT_WEEK_NUM);
//                StartEndTime monthStartEndTime = LogServiceHelper.getCurrentLogSearchEndTime(date, AdminConstants.STAT_MONTH_NUM);
//
//                metaverseServerService.collectMetaverseServerCount(dayStartEndTime.getStartTime(), dayStartEndTime.getEndTime(), 13);
//                capacityService.collectDBCapacity(dayStartEndTime.getStartTime(), dayStartEndTime.getEndTime());  //체크
//                dauService.collectDailyActiveUser(dayStartEndTime.getStartTime(), dayStartEndTime.getEndTime());  //체크
//                wauService.collectWeeklyActiveUser(weekStartEndTime.getStartTime(), weekStartEndTime.getEndTime());   //체크
//                mauService.collectMonthlyActiveUser(monthStartEndTime.getStartTime(), monthStartEndTime.getEndTime());    //체크
//                mcuService.collectMaxCountUser(dayStartEndTime.getStartTime(), dayStartEndTime.getEndTime());     //체크
//                nruService.collectCharacterCreateCount(dayStartEndTime.getStartTime(), dayStartEndTime.getEndTime());     //체크
//                playTimeService.collectUserPlayTime(dayStartEndTime.getStartTime(), dayStartEndTime.getEndTime());    //체크
//                dglcService.collectDailyGameLoginCount(dayStartEndTime.getStartTime(), dayStartEndTime.getEndTime());     //체크
//                ugqCreateService.collectUGQCreateCount(dayStartEndTime.getStartTime(), dayStartEndTime.getEndTime());     //체크
//            }


        }catch (Exception e){
            log.error(e.getMessage());
        }
    }
}
