package com.auth.service.base.service.impl;

import com.auth.common.model.common.result.PageResult;
import com.auth.model.base.dto.RoleDto;
import com.auth.model.base.vo.RoleVo;
import com.auth.dao.base.entity.RoleEntity;
import com.auth.dao.base.mapper.v1.RoleMapper;
import com.auth.service.base.service.RoleService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 系统角色表 服务实现类
 * </p>
 *
 * @author Bunny
 * @since 2025-07-17 23:06:38
 */
@Service
@Transactional
public class RoleServiceImpl extends ServiceImpl<RoleMapper, RoleEntity> implements RoleService {

    /**
     * 系统角色表 服务实现类
     *
     * @param pageParams 系统角色表分页查询page对象
     * @param dto        系统角色表分页查询对象
     * @return 查询分页系统角色表返回对象
     */
    @Override
    public PageResult<RoleVo> getRolePage(Page<RoleEntity> pageParams, RoleDto dto) {
        IPage<RoleVo> page = baseMapper.selectListByPage(pageParams, dto);

        return PageResult.<RoleVo>builder()
                .list(page.getRecords())
                .pageNo(page.getCurrent())
                .pageSize(page.getSize())
                .total(page.getTotal())
                .build();
    }

    /**
     * 根据id查询系统角色表详情
     *
     * @param id 主键
     * @return 系统角色表详情 RoleVo}
     */
    public RoleVo getRoleById(Long id) {
        RoleEntity roleEntity = getById(id);

        RoleVo roleVo = new RoleVo();
        BeanUtils.copyProperties(roleEntity, roleVo);

        return roleVo;
    }

    /**
     * 添加系统角色表
     *
     * @param dto 系统角色表添加
     */
    @Override
    public void addRole(RoleDto dto) {
        RoleEntity role = new RoleEntity();
        BeanUtils.copyProperties(dto, role);

        save(role);
    }

    /**
     * 更新系统角色表
     *
     * @param dto 系统角色表更新
     */
    @Override
    public void updateRole(RoleDto dto) {
        RoleEntity role = new RoleEntity();
        BeanUtils.copyProperties(dto, role);

        updateById(role);
    }

    /**
     * 删除|批量删除系统角色表
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteRole(List<Long> ids) {
        removeByIds(ids);
    }
}