package com.yonge.cooleshow.biz.dal.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yonge.cooleshow.biz.dal.entity.CouponInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yonge.cooleshow.biz.dal.enums.InOrOutEnum;
import com.yonge.cooleshow.biz.dal.queryInfo.CouponInfoQuery;
import com.yonge.cooleshow.biz.dal.queryInfo.CouponInventoryQuery;
import com.yonge.cooleshow.biz.dal.vo.coupon.CouponInfoWrapper;
import com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper;
import com.yonge.cooleshow.biz.dal.wrapper.coupon.CouponInventoryWrapper;
import com.yonge.cooleshow.biz.dal.wrapper.coupon.CouponOrderWrapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 优惠券信息 Mapper 接口
 * </p>
 *
 * @author Eric
 * @since 2022-09-02
 */
@Repository
public interface CouponInfoMapper extends BaseMapper<CouponInfo> {

    /**
     * 分页查询优惠券信息
     *
     * @param page  IPage<CouponInfoWrapper>
     * @param query CouponInfoQuery
     * @return List<CouponInfoWrapper>
     */
    List<CouponInfoWrapper> selectCouponPageInfo(@Param("page") IPage<CouponInfoWrapper> page, @Param("record") CouponInfoQuery query);

    /**
     * 优惠券发放未使用统计
     *
     * @param couponIds 优惠券ID
     * @param query     统计查询条件
     * @return List<StatGroupWrapper>
     */
    List<StatGroupWrapper> selectCouponIssueStatInfo(@Param("couponIds") List<Long> couponIds, @Param("record") CouponInfoQuery.IssueStatQuery query);

    /**
     * 优惠券库存量调整信息
     *
     * @param page  IPage<CouponInventoryWrapper>
     * @param query CouponInventoryQuery
     * @return List<CouponInventoryWrapper>
     */
    List<CouponInventoryWrapper> selectCouponInventoryPageInfo(@Param("page") IPage<CouponInventoryWrapper> page, @Param("record") CouponInventoryQuery query);

    /**
     * 活动优惠券统计
     *
     * @param couponIds 优惠券ID
     * @return List<StatGroupWrapper>
     */
    List<StatGroupWrapper> selectActivityCouponStatInfo(@Param("couponIds") List<Long> couponIds);

    /**
     * 优惠券库存变更
     *
     * @param couponId 优惠券id
     * @param size     变更数量
     * @param inOrOut  增/减状态
     * @return
     */
    int updateStock(@Param("couponId") Long couponId, @Param("size") int size, @Param("inOrOut") InOrOutEnum inOrOut);

    /**
     * 用户订单优惠券信息
     * @param userid 用户ID
     * @param query CouponInfoQuery.CouponOrderQuery
     * @return List<CouponOrderWrapper.CouponInfo>
     */
    List<CouponOrderWrapper.CouponInfo> selectUserOrderCouponInfo(@Param("userId") Long userid, @Param("record") CouponInfoQuery.CouponOrderQuery query);
}
