package cn.iocoder.yudao.module.system.api.dept;

import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
import cn.iocoder.yudao.module.system.service.dept.DeptService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 * 部门 API 实现类
 *
 * @author 芋道源码
 */
@Service
public class DeptApiImpl implements DeptApi {

    @Resource
    private DeptService deptService;

    @Override
    public DeptRespDTO getDept(Long id) {
        DeptDO dept = deptService.getDept(id);
        return BeanUtils.toBean(dept, DeptRespDTO.class);
    }

    @Override
    public DeptRespDTO getDeptNoPermission(Long id) {
        DeptDO dept = deptService.getDeptNoPermission(id);
        return BeanUtils.toBean(dept, DeptRespDTO.class);
    }

    @Override
    public List<DeptRespDTO> getDeptList(Collection<Long> ids) {
        List<DeptDO> depts = deptService.getDeptList(ids);
        return BeanUtils.toBean(depts, DeptRespDTO.class);
    }

    @Override
    public List<DeptRespDTO> getDeptList() {
        DeptListReqVO reqVO = new DeptListReqVO();
        List<DeptDO> depts = deptService.getDeptList(reqVO);
        return BeanUtils.toBean(depts, DeptRespDTO.class);
    }

    @Override
    public List<DeptRespDTO> ignoredTenantDepts() {
        DeptListReqVO reqVO = new DeptListReqVO();
        List<DeptDO> depts = deptService.ignoredTenantDepts(reqVO);
        return BeanUtils.toBean(depts, DeptRespDTO.class);
    }

    @Override
    public void validateDeptList(Collection<Long> ids) {
        deptService.validateDeptList(ids);
    }

    @Override
    public List<DeptRespDTO> getChildDeptList(Long id) {
        List<DeptDO> childDeptList = deptService.getChildDeptList(id);
        return BeanUtils.toBean(childDeptList, DeptRespDTO.class);
    }

    @Override
    public List<DeptRespDTO> getDeptByName(String deptName) {
        List<DeptDO> deptByName = deptService.getDeptByName(deptName);
        return BeanUtils.toBean(deptByName, DeptRespDTO.class);
    }
    @Override
    public List<DeptRespDTO> getDeptByNamePermission(String deptName) {
        List<DeptDO> deptByName = deptService.getDeptByNameNoPermission(deptName);
        return BeanUtils.toBean(deptByName, DeptRespDTO.class);
    }

}
