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

import com.jeesharp.business.modules.coupon.stats.mapper.CouponStatsMapper;
import com.jeesharp.business.modules.coupon.stats.service.CouponStatsService;
import com.jeesharp.business.modules.coupon.stats.vo.CouponStatsDateCountVO;
import com.jeesharp.business.modules.coupon.stats.vo.CouponStatsTemplateRankRowVO;
import com.jeesharp.business.modules.coupon.stats.vo.CouponStatsTenantScope;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * 优惠券统计领域服务实现。
 *
 * @author jeesharp
 * @since 2026-07-03
 */
@Service
@AllArgsConstructor
public class CouponStatsServiceImpl implements CouponStatsService {

    private final CouponStatsMapper couponStatsMapper;

    @Override
    public long countCouponTemplate(CouponStatsTenantScope scope, Integer status) {
        Long count = couponStatsMapper.countCouponTemplate(scope, status);
        return count != null ? count : 0L;
    }

    @Override
    public long countMemberCoupon(CouponStatsTenantScope scope, Integer status, String getSource,
                                  LocalDateTime startDateTime, LocalDateTime endDateTime) {
        Long count = couponStatsMapper.countMemberCoupon(scope, status, getSource, startDateTime, endDateTime);
        return count != null ? count : 0L;
    }

    @Override
    public List<CouponStatsDateCountVO> dailyClaimByGetDate(CouponStatsTenantScope scope,
                                                            LocalDateTime startDateTime,
                                                            LocalDateTime endDateTime) {
        return couponStatsMapper.dailyClaimByGetDate(scope, startDateTime, endDateTime);
    }

    @Override
    public List<CouponStatsDateCountVO> dailyGrantByGetDate(CouponStatsTenantScope scope, String getSource,
                                                            LocalDateTime startDateTime,
                                                            LocalDateTime endDateTime) {
        return couponStatsMapper.dailyGrantByGetDate(scope, getSource, startDateTime, endDateTime);
    }

    @Override
    public List<CouponStatsDateCountVO> dailyUseByUseDate(CouponStatsTenantScope scope,
                                                         LocalDateTime startDateTime,
                                                         LocalDateTime endDateTime) {
        return couponStatsMapper.dailyUseByUseDate(scope, startDateTime, endDateTime);
    }

    @Override
    public List<CouponStatsTemplateRankRowVO> topClaimTemplates(CouponStatsTenantScope scope, int limit) {
        return couponStatsMapper.topClaimTemplates(scope, limit);
    }
}
