package com.seer.teach.user.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.seer.teach.user.entity.RoleEntity;
import com.seer.teach.user.mapper.RoleMapper;
import com.seer.teach.user.service.IRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Wang
 * @since 2025-07-16 17:01:56
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, RoleEntity> implements IRoleService {

    @Override
    public Optional<RoleEntity> getRoleByName(String name) {
        return Optional.ofNullable(super.getOne(new LambdaQueryWrapper<>(RoleEntity.class).eq(RoleEntity::getRoleName, name)));
    }

    @Override
    public Optional<RoleEntity> getRoleByCode(String roleCode) {
        return Optional.ofNullable(super.getOne(new LambdaQueryWrapper<>(RoleEntity.class).eq(RoleEntity::getRoleCode, roleCode)));
    }

    @Override
    public Collection<RoleEntity> getRoleListByRoleIds(Collection<Integer> roleIds) {
        if (CollUtil.isEmpty(roleIds)){
            return Collections.emptyList();
        }
        return super.list(new LambdaQueryWrapper<>(RoleEntity.class).in(RoleEntity::getId, roleIds));
    }
}