package com.izouma.nineth.service;

import com.izouma.nineth.repo.AwardActivityCollectionInfoRepo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 收集活动 可兑换藏品service
 *
 * @author ZouYuHong
 */
@Slf4j
@Service
@AllArgsConstructor
public class AwardActivityCollectionService {

    private final AwardActivityCollectionInfoRepo repo;

    /**
     * 获取库存
     *
     * @param activityId   活动ID
     * @param collectionId 藏品ID
     * @return 库存
     */
    public synchronized Integer getStock(Long activityId, Long collectionId) {
        return repo.selectByActivityIdAndCollectionId(activityId, collectionId);
    }


    /**
     * 更新剩余库存
     *
     * @param activityId   藏品Id
     * @param collectionId 集合ID
     * @param stock        更新的库存
     */
    public void updateStock(Long activityId, Long collectionId, int stock) {
        repo.updateStock(activityId, collectionId, stock);
    }

    public Long findLastActivityByCollectionId(Long collectionId) {
        return repo.selectLastActivityIdByCollectionId(collectionId);
    }

    public void softDeleteByActivityId(Long activityId) {
        repo.softDeleteByActivityId(activityId);
    }
}
