package com.zioinfo.mall.loyalty.mapper;

import com.zioinfo.mall.loyalty.MallPointLedger;
import com.zioinfo.mall.loyalty.MallTierBenefit;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

@Mapper
public interface LoyaltyMapper {
    // 등급 혜택 정의
    List<MallTierBenefit> findTiers(@Param("activeOnly") Boolean activeOnly);
    MallTierBenefit findTierByCode(@Param("tierCode") String tierCode);
    MallTierBenefit findTierById(@Param("id") Long id);
    int insertTier(MallTierBenefit t);
    int updateTier(MallTierBenefit t);
    int deleteTier(@Param("id") Long id);

    // 12개월 누적 구매 집계 (주문 PAID 이후 상태)
    Map<String, Object> spend12m(@Param("owner") String owner);

    // 회원 등급 sync (mall_member.tier)
    int updateMemberTier(@Param("username") String username, @Param("tier") String tier);
    List<String> allMemberUsernames();

    // 포인트 원장
    int insertPoint(MallPointLedger e);
    Integer balance(@Param("owner") String owner);
    List<MallPointLedger> history(@Param("owner") String owner, @Param("limit") int limit);

    // 등급별 매출 (analytics)
    List<Map<String, Object>> salesByTier(@Param("days") int days);
}
