package com.czg.service.account.mapper;

import com.czg.account.dto.shopuser.ShopUserDTO;
import com.czg.account.dto.shopuser.ShopUserSummaryDTO;
import com.czg.account.dto.shopuser.ShopUserVipCardDTO;
import com.czg.account.dto.user.userinfo.UserInfoAssetsSummaryDTO;
import com.czg.account.entity.ShopUser;
import com.czg.market.entity.SmsPushEventUser;
import com.czg.market.vo.InviteUserVO;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

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

/**
 * 商户储值会员 映射层。
 *
 * @author Administrator
 * @since 2025-02-08
 */
public interface ShopUserMapper extends BaseMapper<ShopUser> {

    List<ShopUserDTO> selectPageByKeyAndIsVip(@Param("shopId") Long shopId, @Param("isVip") Integer isVip, @Param("key") String key, @Param("amount") BigDecimal amount);

    int incrAccount(@Param("id") Long id, @Param("time") LocalDateTime time, @Param("money") BigDecimal money);

    int decrAccount(@Param("id") Long id, @Param("time") LocalDateTime time, @Param("money") BigDecimal money);

    ShopUserSummaryDTO selectUserSummary(@Param("shopId") Long shopId, @Param("isVip") Integer isVip);

    Page<ShopUserVipCardDTO> selectVipCard();

    long selectVipCard_COUNT();

    UserInfoAssetsSummaryDTO selectAssetsSummary(@Param("userId") Long userInfoId);

    /**
     * 查询符合推送条件的用户 手机号不为空
     *
     * @param mainShopId       主店铺ID
     * @param shopId           店铺ID
     * @return 分页结果
     */
    List<ShopUser> selectPushEventUser(
            @Param("mainShopId") Long mainShopId,
            @Param("shopId") Long shopId,
            @Param("param") SmsPushEventUser smsPushEventUser
    );

    /**
     * 查询符合推送条件的用户 公众号Id不为空
     *
     * @param mainShopId       主店铺ID
     * @param shopId           店铺ID
     * @return 分页结果
     */
    List<ShopUser> selectAcPushEventUser(
            @Param("mainShopId") Long mainShopId,
            @Param("shopId") Long shopId,
            @Param("param") SmsPushEventUser smsPushEventUser
    );


    /**
     * 查询邀请用户
     *
     * @param distributionUserId 分销员ID
     * @return 分页结果
     */
    List<InviteUserVO> getInviteUser(Long distributionUserId, Long shopId, Long shopUserId, Long distributionLevelId);

    void updateOneOrTwoAmount(Long shopUserId, Long shopId, BigDecimal amount, Integer isOne);

    @Update("update tb_shop_user set member_level_id = #{newMemberLevelId} where member_level_id = #{oldMemberLevelId}")
    void upMemberLevel(Long newMemberLevelId, Long oldMemberLevelId);
}
