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

import com.auth.common.model.common.result.PageResult;
import com.auth.model.base.dto.MenuDto;
import com.auth.model.base.vo.MenuVo;
import com.auth.dao.base.entity.MenuEntity;
import com.auth.dao.base.mapper.v1.MenuMapper;
import com.auth.service.base.service.MenuService;
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 MenuServiceImpl extends ServiceImpl<MenuMapper, MenuEntity> implements MenuService {

    /**
     * 系统菜单权限 服务实现类
     *
     * @param pageParams 系统菜单权限分页查询page对象
     * @param dto        系统菜单权限分页查询对象
     * @return 查询分页系统菜单权限返回对象
     */
    @Override
    public PageResult<MenuVo> getMenuPage(Page<MenuEntity> pageParams, MenuDto dto) {
        IPage<MenuVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 根据id查询系统菜单权限详情
     *
     * @param id 主键
     * @return 系统菜单权限详情 MenuVo}
     */
    public MenuVo getMenuById(Long id) {
        MenuEntity menuEntity = getById(id);

        MenuVo menuVo = new MenuVo();
        BeanUtils.copyProperties(menuEntity, menuVo);

        return menuVo;
    }

    /**
     * 添加系统菜单权限
     *
     * @param dto 系统菜单权限添加
     */
    @Override
    public void addMenu(MenuDto dto) {
        MenuEntity menu = new MenuEntity();
        BeanUtils.copyProperties(dto, menu);

        save(menu);
    }

    /**
     * 更新系统菜单权限
     *
     * @param dto 系统菜单权限更新
     */
    @Override
    public void updateMenu(MenuDto dto) {
        MenuEntity menu = new MenuEntity();
        BeanUtils.copyProperties(dto, menu);

        updateById(menu);
    }

    /**
     * 删除|批量删除系统菜单权限
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteMenu(List<Long> ids) {
        removeByIds(ids);
    }
}