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

import cn.ey.biz.common.pojo.PageResult;
import cn.ey.biz.common.pojo.R;
import cn.ey.biz.module.system.api.appuser.dto.AppUserCreateReqDTO;
import cn.ey.biz.module.system.api.appuser.dto.AppUserDTO;
import cn.ey.biz.module.system.api.appuser.dto.AppUserPageReqDTO;
import cn.ey.biz.module.system.api.appuser.dto.AppUserRespDTO;
import cn.ey.biz.module.system.controller.admin.appuser.vo.AppUserPageReqVO;
import cn.ey.biz.module.system.controller.admin.appuser.vo.AppUserPageRespVO;
import cn.ey.biz.module.system.controller.admin.appuser.vo.AppUserRespVO;
import cn.ey.biz.module.system.convert.appuser.AppUserConvert;
import cn.ey.biz.module.system.service.appuser.AppUserService;
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 static cn.ey.biz.module.system.enums.ApiConstants.VERSION;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@DubboService(version = VERSION) // 提供 Dubbo RPC 接口，给 Dubbo Consumer 调用
@Validated
public class AppUserApiImpl implements AppUserApi {

    @Resource
    private AppUserService appUserService;

    @Override
    public R<PageResult<AppUserDTO>> getAppUserPage(AppUserPageReqDTO appUserPageReqDTO) {
        AppUserPageReqVO appUserPageReqVO = AppUserConvert.INSTANCE.dtoToVo(appUserPageReqDTO);
        PageResult<AppUserPageRespVO> appUserPage = appUserService.getAppUserPage(appUserPageReqVO);
        return R.success(AppUserConvert.INSTANCE.voToDto(appUserPage));
    }

    @Override
    public R<Long> createAppUser(AppUserCreateReqDTO createReqDTO) {
        return R.success(appUserService.createAppUser(AppUserConvert.INSTANCE.createDtoToVo(createReqDTO)));
    }

    @Override
    public R<Boolean> updateAppUserStatus(AppUserCreateReqDTO createReqDTO) {
        appUserService.updateAppUserStatus(AppUserConvert.INSTANCE.createDtoToVo(createReqDTO));
        return R.success(true);
    }

    @Override
    public R<AppUserRespDTO> getAppUser(Long id) {
        AppUserRespVO appUser = appUserService.getAppUser(id);
        AppUserRespDTO appUserRespDTO = AppUserConvert.INSTANCE.voToDTO(appUser);
        return R.success(appUserRespDTO);
    }

}
