package com.zcloud.basic.info.facade;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.SingleResponse;
import com.zcloud.basic.info.api.UserServiceI;
import com.zcloud.basic.info.command.convertor.UserCoConvertor;
import com.zcloud.basic.info.dto.clientobject.UserCO;
import com.zcloud.basic.info.persistence.dataobject.UserDO;
import com.zcloud.basic.info.persistence.dataobject.UserImgDO;
import com.zcloud.basic.info.persistence.repository.UserRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.gbscommon.zclouduser.facade.ZcloudUserFacade;
import com.zcloud.gbscommon.zclouduser.request.*;
import com.zcloud.gbscommon.zclouduser.response.ZcloudUserCo;
import com.zcloud.gbscommon.zclouduser.response.ZcloudUserImgBase64Co;
import org.apache.dubbo.config.annotation.DubboService;

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

/**
 * @author lin
 */
@DubboService
public class ZcloudUserFacadeImpl implements ZcloudUserFacade {
    @Resource
    private UserServiceI userServiceI;
    @Resource
    private UserCoConvertor userCoConvertor;

    @Resource
    private UserRepository userRepository;

    @Override
    public MultiResponse<ZcloudUserCo> listByUserIdAndDeptId() {
        System.out.println("listByUserIdAndDeptId");
        ZcloudUserCo zcloudUserCo = new ZcloudUserCo();
        zcloudUserCo.setName("hello word");
        ArrayList<ZcloudUserCo> objects = new ArrayList<>();
        objects.add(zcloudUserCo);
        return MultiResponse.of(objects);
    }

    @Override
    public SingleResponse<ZcloudUserCo> getInfoByUserId(Long aLong) {
        UserCO user = userServiceI.getInfoByUserId(aLong);
        ZcloudUserCo zcloudUserCo = userCoConvertor.converCOToDubboCO(user);
        return SingleResponse.of(zcloudUserCo);
    }

    @Override
    public MultiResponse<ZcloudUserCo> listByUserIds(Collection<Long> collection) {
        List<UserCO> users = userServiceI.listByUserIds(collection);
        List<ZcloudUserCo> zcloudUserCo = userCoConvertor.converCOsToDubboCOs(users);
        return MultiResponse.of(zcloudUserCo);
    }

    @Override
    public MultiResponse<ZcloudUserCo> getUserList() {
        List<UserCO> users = userServiceI.getUserList();
        List<ZcloudUserCo> zcloudUserCo = userCoConvertor.converCOsToDubboCOs(users);
        return MultiResponse.of(zcloudUserCo);
    }

    @Override
    public MultiResponse<ZcloudUserCo> listUserByUserName(Collection<String> collection) {
        List<UserCO> users = userServiceI.listUserByUserName(collection);
        List<ZcloudUserCo> zcloudUserCo = userCoConvertor.converCOsToDubboCOs(users);
        return MultiResponse.of(zcloudUserCo);
    }

    @Override
    public MultiResponse<ZcloudUserCo> listUserByUserNameV1(Collection<String> collection) {
        List<UserCO> users = userServiceI.listUserByUserNameV1(collection);
        List<ZcloudUserCo> zcloudUserCo = userCoConvertor.converCOsToDubboCOs(users);
        return MultiResponse.of(zcloudUserCo);
    }

    @Override
    public MultiResponse<ZcloudUserCo> listUserByCorpInfoId(ZcloudUserQry zcloudUserQry) {
        Map<String, Object> parmas = PageQueryHelper.toHashMap(zcloudUserQry);
        List<UserDO> userList = userRepository.listAll(parmas);
        List<ZcloudUserCo> zcloudUserCos = userCoConvertor.converDOsToDubboCOs(userList);
        return MultiResponse.of(zcloudUserCos);
    }

    @Override
    public MultiResponse<ZcloudUserImgBase64Co> listBase64ByUrl(ZcloudUserImgQry zcloudUserImgQry) {
        Map<String, Object> parmas = PageQueryHelper.toHashMap(zcloudUserImgQry);
        List<UserImgDO> list = userServiceI.listBase64ByUrl(parmas);
        List<ZcloudUserImgBase64Co> zcloudUserImgBase64Cos = BeanUtil.copyToList(list, ZcloudUserImgBase64Co.class);
        return MultiResponse.of(zcloudUserImgBase64Cos);
    }

    @Override
    public SingleResponse addHumanUser(ZcloudUserAddCmd zcloudUserAddCmd) {
        return null;
    }

    @Override
    public SingleResponse<Long> updateHumanUser(ZcloudUserUpdateCmd zcloudUserUpdateCmd) {
        return null;
    }

    @Override
    public MultiResponse<ZcloudUserCo> listUserByInfo(ZcloudUserInfoQry zcloudUserInfoQry) {
        return null;
    }

}
