package com.its.vds.stat.server.service;

import com.its.vds.stat.server.annotation.ProcessingElapsed;
import com.its.vds.stat.server.dao.repository.VdsStatRepository;
import com.its.vds.stat.server.dto.VdsStatTimeDto;
import com.its.vds.stat.server.utils.TimeUtils;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Getter
@RequiredArgsConstructor
@Service
@Transactional(rollbackFor = { Exception.class })
public class VdsStatServerService {

    private final VdsStatRepository repo;

    @ProcessingElapsed(type="05MIN", name="VDS 5분 통계", starting = false)
    public int delVdsDtctHs(String statDt) {
//        log.info("delVdsDtctHs: statDt: {}", statDt);
        VdsStatTimeDto statTime = new VdsStatTimeDto(statDt, statDt, statDt);
        return this.repo.delVdsDtctHs(statTime);
    }

    @ProcessingElapsed(type="05MIN", name="VDS 15분 통계", starting = false)
    public int delVdsDtct15MinStat(String statDt) {
//        log.info("delVdsDtct15MinStat: statDt: {}", statDt);
        VdsStatTimeDto statTime = new VdsStatTimeDto(statDt, statDt, statDt);
        return this.repo.delVdsDtct15MinStat(statTime);
    }

    @ProcessingElapsed(type="05MIN", name="VDS 1시간 통계", starting = false)
    public int delVdsDtctHhStat(String statDt) {
//        log.info("delVdsDtctHhStat: statDt: {}", statDt);
        VdsStatTimeDto statTime = new VdsStatTimeDto(statDt, statDt, statDt);
        return this.repo.delVdsDtctHhStat(statTime);
    }

    @ProcessingElapsed(type="05MIN", name="VDS 일 통계", starting = false)
    public int delVdsDtctDdStat(String statDt) {
//        log.info("delVdsDtctDdStat: statDt: {}", statDt);
        VdsStatTimeDto statTime = new VdsStatTimeDto(statDt, statDt, statDt);
        return this.repo.delVdsDtctDdStat(statTime);
    }



    @ProcessingElapsed(type="05MIN", name="VDS 5분 통계", starting = false)
    public int crtVdsDtctHs(String statDt, String fromDt, String toDt) {
        log.info("crtVdsDtctHs: currDt: {} statDt: {}, fromDt: {}, toDt: {}", TimeUtils.getCurrentTimeString(), statDt, fromDt, toDt);
        VdsStatTimeDto statTime = new VdsStatTimeDto(statDt, fromDt, toDt);
        return this.repo.crtVdsDtctHs(statTime);
    }

    @ProcessingElapsed(type="05MIN", name="VDS 15분 통계", starting = false)
    public int crtVdsDtct15MinStat(String statDt, String fromDt, String toDt) {
        log.info("crtVdsDtct15MinStat: currDt: {} statDt: {}, fromDt: {}, toDt: {}", TimeUtils.getCurrentTimeString(), statDt, fromDt, toDt);
        VdsStatTimeDto statTime = new VdsStatTimeDto(statDt, fromDt, toDt);
        return this.repo.crtVdsDtct15MinStat(statTime);
    }

    @ProcessingElapsed(type="05MIN", name="VDS 1시간 통계", starting = false)
    public int crtVdsDtctHhStat(String statDt, String fromDt, String toDt) {
        log.info("crtVdsDtctHhStat: currDt: {} statDt: {}, fromDt: {}, toDt: {}", TimeUtils.getCurrentTimeString(), statDt, fromDt, toDt);
        VdsStatTimeDto statTime = new VdsStatTimeDto(statDt, fromDt, toDt);
        return this.repo.crtVdsDtctHhStat(statTime);
    }

    @ProcessingElapsed(type="05MIN", name="VDS 일 통계", starting = false)
    public int crtVdsDtctDdStat(String statDt, String fromDt, String toDt) {
        log.info("crtVdsDtctDdStat: currDt: {} statDt: {}, fromDt: {}, toDt: {}", TimeUtils.getCurrentTimeString(), statDt, fromDt, toDt);
        VdsStatTimeDto statTime = new VdsStatTimeDto(statDt, fromDt, toDt);
        return this.repo.crtVdsDtctDdStat(statTime);
    }

    @ProcessingElapsed(type="05MIN", name="VDS 월 통계", starting = false)
    public int crtVdsDtctMnStat(String statDt, String fromDt, String toDt) {
        log.info("crtVdsDtctMnStat: currDt: {} statDt: {}, fromDt: {}, toDt: {}", TimeUtils.getCurrentTimeString(), statDt, fromDt, toDt);
        VdsStatTimeDto statTime = new VdsStatTimeDto(statDt, fromDt, toDt);
        return this.repo.crtVdsDtctMnStat(statTime);
    }

    @ProcessingElapsed(type="05MIN", name="VDS 년 통계", starting = false)
    public int crtVdsDtctYyStat(String statDt, String fromDt, String toDt) {
        log.info("crtVdsDtctYyStat: currDt: {} statDt: {}, fromDt: {}, toDt: {}", TimeUtils.getCurrentTimeString(), statDt, fromDt, toDt);
        VdsStatTimeDto statTime = new VdsStatTimeDto(statDt, fromDt, toDt);
        return this.repo.crtVdsDtctYyStat(statTime);
    }

}
