package com.starry.admin.modules.blindbox.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.starry.admin.common.exception.CustomException;
import com.starry.admin.modules.blindbox.mapper.BlindBoxConfigMapper;
import com.starry.admin.modules.blindbox.module.constant.BlindBoxConfigStatus;
import com.starry.admin.modules.blindbox.module.entity.BlindBoxConfigEntity;
import com.starry.admin.modules.blindbox.service.BlindBoxConfigService;
import java.util.List;
import org.springframework.stereotype.Service;

@Service
public class BlindBoxConfigServiceImpl
        extends ServiceImpl<BlindBoxConfigMapper, BlindBoxConfigEntity>
        implements BlindBoxConfigService {

    @Override
    public BlindBoxConfigEntity requireById(String id) {
        BlindBoxConfigEntity entity = getById(id);
        if (entity == null) {
            throw new CustomException("盲盒不存在");
        }
        return entity;
    }

    @Override
    public List<BlindBoxConfigEntity> listActiveByTenant(String tenantId) {
        return lambdaQuery()
                .eq(BlindBoxConfigEntity::getTenantId, tenantId)
            .eq(BlindBoxConfigEntity::getStatus, BlindBoxConfigStatus.ENABLED.getCode())
                .eq(BlindBoxConfigEntity::getDeleted, Boolean.FALSE)
                .list();
    }
}
