package com.sckw.system.service;

import com.sckw.core.utils.BeanUtils;
import com.sckw.core.web.response.BaseResult;
import com.sckw.system.model.AppVersions;
import com.sckw.system.model.vo.res.AppVersionsResVo;
import com.sckw.system.repository.AppVersionsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author :chenXiaoFei
 * @version :1.0
 * @description : 版本管理相关接口
 * @create :2026-01-07 15:50:00
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class KwsAppVersionsService {

    private final AppVersionsService appVersionsService;

    public AppVersionsResVo getLatestVersion(Integer platform) {
        log.info("查询最新版本信息，平台类型: {}", platform);
        AppVersions latestVersion = appVersionsService.getLatestVersion(platform);
        if (latestVersion == null) {
            return new AppVersionsResVo();
        }
        
        return AppVersionsResVo.builder()
                .id(latestVersion.getId())
                .versionCode(latestVersion.getVersionCode())
                .platform(latestVersion.getPlatform())
                .downloadUrl(latestVersion.getDownloadUrl())
                .isForceUpdate(latestVersion.getIsForceUpdate())
                .build();
    }
}
