package com.izouma.nineth.service.rewardpoints;

import com.izouma.nineth.domain.PointActivityAward;
import com.izouma.nineth.exception.BusinessException;
import com.izouma.nineth.repo.rewardpoints.PointActivityAwardRepo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 积分活动 藏品Service
 */
@Slf4j
@Service
@AllArgsConstructor
public class PointActivityAwardService {
    private final PointActivityAwardRepo pointActivityAwardRepo;

    public List<PointActivityAward> saveAwards(List<PointActivityAward> awards) {
        return pointActivityAwardRepo.saveAll(awards);
    }

    public List<PointActivityAward> activityAwards(Long id) {
        return pointActivityAwardRepo.selectByActivityId(id);
    }

    public void decreaseStock(Long id, int num) {
        pointActivityAwardRepo.decreaseStock(id,num);
        pointActivityAwardRepo.flush();
    }

    public void softDelByActivityId(Long activityId) {
        pointActivityAwardRepo.softDelByActivityId(activityId);
    }

    public PointActivityAward findAwardById(Long id){
        return pointActivityAwardRepo.findById(id).orElseThrow(new BusinessException("您查找的藏品不存在"));
    }
}
