package cn.ey.biz.module.system.api.delegation;

import cn.ey.biz.common.pojo.R;
import cn.ey.biz.module.system.api.delegation.dto.UserDelegationDTO;
import cn.ey.biz.module.system.api.delegation.dto.UserDelegationReqDTO;
import cn.ey.biz.module.system.api.delegation.dto.UserDelegationUnitDTO;
import cn.ey.biz.module.system.convert.delegation.DelegationConvert;
import cn.ey.biz.module.system.dal.dataobject.delegation.UserDelegationDO;
import cn.ey.biz.module.system.service.delegation.UserDelegationService;
import cn.ey.biz.module.system.service.delegation.UserDelegationUnitService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

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

import static cn.ey.biz.module.system.enums.ApiConstants.VERSION;

@RestController
@DubboService(version = VERSION) // 提供 Dubbo RPC 接口，给 Dubbo Consumer 调用
@Validated
public class DelegationApiImpl implements DelegationApi {

    @Resource
    private UserDelegationService userDelegationService;
    @Resource
    private UserDelegationUnitService userDelegationUnitService;

    @Override
    public List<UserDelegationDTO> getDelegation(String app, String gpn) {
        return userDelegationService.getUserDelegation(app, gpn);
    }

    @Override
    public List<UserDelegationUnitDTO> getDelegationUnit(String app, String gpn, String type) {
        return userDelegationUnitService.getDelegationUnit(app, gpn, type);
    }

    @Override
    public R<List<UserDelegationDTO>> listDelegation(UserDelegationReqDTO userDelegationReq) {
        List<UserDelegationDO> userDelegationEntities = userDelegationService.listDelegation(userDelegationReq);
        return R.success(DelegationConvert.INSTANCE.convertList2DTO(userDelegationEntities));
    }
}
