package com.jeesharp.business.modules.member.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jeesharp.business.modules.member.entity.MemberLevelFeature;
import com.jeesharp.business.modules.member.mapper.MemberLevelFeatureMapper;
import com.jeesharp.business.modules.member.service.MemberLevelFeatureService;
import com.jeesharp.business.modules.member.vo.MemberLevelFeatureQueryVO;
import com.jeesharp.framework.mybatis.core.service.CrudService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;

/**
 * 会员等级功能权限服务实现类
 *
 * @author jeesharp
 * @version 2024-01-24
 */
@Service
@Transactional(readOnly = true)
public class MemberLevelFeatureServiceImpl extends CrudService<MemberLevelFeatureMapper, MemberLevelFeature, MemberLevelFeatureQueryVO> implements MemberLevelFeatureService {

    @Override
    public List<String> getFeatureCodesByLevelSort(Integer levelSort, String tenantId) {
        if (levelSort == null) {
            levelSort = 1;
        }
        List<String> list = baseMapper.selectFeatureCodesByLevelSort(levelSort, tenantId);
        return list != null ? list : Collections.emptyList();
    }

    @Override
    public List<MemberLevelFeature> listByFeatureCodes(List<String> featureCodes) {
        if (CollUtil.isEmpty(featureCodes)) {
            return Collections.emptyList();
        }
        LambdaQueryWrapper<MemberLevelFeature> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(MemberLevelFeature::getFeatureCode, featureCodes)
                .eq(MemberLevelFeature::getStatus, 1);
        return list(wrapper);
    }
}
