package com.jeesharp.business.modules.marketing.stats.service.impl;

import com.jeesharp.business.modules.marketing.stats.mapper.MarketingStatsMapper;
import com.jeesharp.business.modules.marketing.stats.service.MarketingStatsService;
import com.jeesharp.business.modules.marketing.stats.vo.MarketingStatsChannelItemVO;
import com.jeesharp.business.modules.marketing.stats.vo.MarketingStatsDailyTrendItemVO;
import com.jeesharp.business.modules.marketing.stats.vo.MarketingStatsQueryVO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;

/**
 * 会员营销统计领域服务实现。
 *
 * @author jeesharp
 * @since 2026-06-25
 */
@Service
@AllArgsConstructor
@Transactional(readOnly = true)
public class MarketingStatsServiceImpl implements MarketingStatsService {

    private final MarketingStatsMapper marketingStatsMapper;

    @Override
    public Long countJoin(MarketingStatsQueryVO query, LocalDateTime startDateTime, LocalDateTime endDateTime) {
        Long count = marketingStatsMapper.countJoin(query, startDateTime, endDateTime);
        return count != null ? count : 0L;
    }

    @Override
    public Long countVerify(MarketingStatsQueryVO query, LocalDateTime startDateTime, LocalDateTime endDateTime) {
        Long count = marketingStatsMapper.countVerify(query, startDateTime, endDateTime);
        return count != null ? count : 0L;
    }

    @Override
    public List<MarketingStatsDailyTrendItemVO> dailyJoin(MarketingStatsQueryVO query, LocalDateTime startDateTime, LocalDateTime endDateTime) {
        List<MarketingStatsDailyTrendItemVO> list = marketingStatsMapper.dailyJoin(query, startDateTime, endDateTime);
        return list != null ? list : Collections.emptyList();
    }

    @Override
    public List<MarketingStatsDailyTrendItemVO> dailyVerify(MarketingStatsQueryVO query, LocalDateTime startDateTime, LocalDateTime endDateTime) {
        List<MarketingStatsDailyTrendItemVO> list = marketingStatsMapper.dailyVerify(query, startDateTime, endDateTime);
        return list != null ? list : Collections.emptyList();
    }

    @Override
    public List<MarketingStatsChannelItemVO> channelJoin(MarketingStatsQueryVO query, LocalDateTime startDateTime, LocalDateTime endDateTime) {
        List<MarketingStatsChannelItemVO> list = marketingStatsMapper.channelJoin(query, startDateTime, endDateTime);
        return list != null ? list : Collections.emptyList();
    }

    @Override
    public List<MarketingStatsChannelItemVO> channelVerify(MarketingStatsQueryVO query, LocalDateTime startDateTime, LocalDateTime endDateTime) {
        List<MarketingStatsChannelItemVO> list = marketingStatsMapper.channelVerify(query, startDateTime, endDateTime);
        return list != null ? list : Collections.emptyList();
    }
}
