package com.ruoyi.ss.userCard.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.ss.userCard.mapper.UserCardMapper;
import com.ruoyi.ss.userCard.domain.UserCard;
import com.ruoyi.ss.userCard.domain.UserCardVO;
import com.ruoyi.ss.userCard.domain.UserCardQuery;
import com.ruoyi.ss.userCard.service.IUserCardService;

import static com.ruoyi.common.constant.ServiceConstants.CARD_STATUS_UNUSED;

/**
 * 用户卡券Service业务层处理
 *
 * @author qzz
 * @date 2025-03-19
 */
@Service
public class UserCardServiceImpl implements IUserCardService
{
    @Autowired
    private UserCardMapper userCardMapper;

    /**
     * 查询用户卡券
     *
     * @param recordId 用户卡券主键
     * @return 用户卡券
     */
    @Override
    public UserCardVO selectUserCardById(Long recordId)
    {
        return userCardMapper.selectUserCardById(recordId);
    }

    /**
     * 查询用户卡券列表
     *
     * @param userCard 用户卡券
     * @return 用户卡券
     */
    @Override
    public List<UserCardVO> selectUserCardList(UserCardQuery userCard)
    {
        return userCardMapper.selectUserCardList(userCard);
    }

    /**
     * 新增用户卡券
     *
     * @param userCard 用户卡券
     * @return 结果
     */
    @Override
    public int insertUserCard(UserCard userCard)
    {
        return userCardMapper.insertUserCard(userCard);
    }

    /**
     * 修改用户卡券
     *
     * @param userCard 用户卡券
     * @return 结果
     */
    @Override
    public int updateUserCard(UserCard userCard)
    {
        return userCardMapper.updateUserCard(userCard);
    }

    /**
     * 批量删除用户卡券
     *
     * @param recordIds 需要删除的用户卡券主键
     * @return 结果
     */
    @Override
    public int deleteUserCardByRecordIds(Long[] recordIds)
    {
        return userCardMapper.deleteUserCardByIds(recordIds);
    }

    /**
     * 删除用户卡券信息
     *
     * @param recordId 用户卡券主键
     * @return 结果
     */
    @Override
    public int deleteUserCardByRecordId(Long recordId)
    {
        return userCardMapper.deleteUserCardById(recordId);
    }

    /**
     * 获取用户可用卡券
     */
    @Override
    public List<UserCardVO> getAvailableCard(Long userId) {
        UserCardQuery userCardQuery = new UserCardQuery();
        userCardQuery.setUserId(userId);
        userCardQuery.setStatus(CARD_STATUS_UNUSED);
        return userCardMapper.selectUserCardList(userCardQuery);
    }
}
