package cn.sikey.tools.service.appversion;

import cn.sikey.tools.controller.app.version.vo.AppUpgradeRespVO;
import cn.sikey.tools.controller.app.version.vo.QueryAppUpgradeReqVO;
import cn.sikey.tools.convert.AppVersionConvert;
import cn.sikey.tools.dal.dataobject.AppVersionUpgradeDO;
import cn.sikey.tools.dal.mysql.AppVersionMapper;
import cn.sikey.tools.enums.CommonResult;
import cn.sikey.tools.enums.GlobalErrorCodeConstants;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * APP版本升级
 */
@Service
@Slf4j
public class AppVersionServiceImpl implements AppVersionService {

    @Resource
    private AppVersionMapper appVersionMapper;

    /**
     * APP升级
     *
     * @param req   请求参数
     * @return      AppUpgradeRespVO
     */
    @Override
    public CommonResult<AppUpgradeRespVO> queryAppUpgrade(QueryAppUpgradeReqVO req) {
        log.info("[获取APP版本信息]请求参数：{}", req);
        AppVersionUpgradeDO appVersionUpgradeDO = appVersionMapper.queryAppUpgrade(req);
        if (Objects.isNull(appVersionUpgradeDO)) {
            return CommonResult.error(GlobalErrorCodeConstants.APP_VERSION_NOT_EXIST_ERROR);
        }
        return CommonResult.success(AppVersionConvert.INSTANCE.convertAppUpgradeRespVO(appVersionUpgradeDO));
    }
}
