package com.fdkankan.ucenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fdkankan.ucenter.entity.Product;
import com.fdkankan.ucenter.entity.SceneCooperation;
import com.fdkankan.ucenter.entity.SceneCooperationCount;
import com.fdkankan.ucenter.mapper.IProductMapper;
import com.fdkankan.ucenter.service.IProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fdkankan.ucenter.service.ISceneCooperationCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2025-03-13
 */
@Service
public class ProductServiceImpl extends ServiceImpl<IProductMapper, Product> implements IProductService {

    @Autowired
    ISceneCooperationCountService sceneCooperationCountService;
    @Override
    public Product getByKey(String key) {
        LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Product::getTypeKey,key);
        List<Product> list = this.list(wrapper);
        if(list.isEmpty()){
            return null;
        }
        return list.get(0);
    }

    @Override
    public Integer getFreeCount(String num,String sceneType) {
        SceneCooperationCount byNum = sceneCooperationCountService.getByNum(num,sceneType);
        if(byNum == null){
            return 1;
        }
        return byNum.getCount();
    }
}
