package com.czg.controller.user;

import com.czg.resp.CzgResult;
import com.czg.system.dto.SysParamsDTO;
import com.czg.system.dto.VersionDTO;
import com.czg.system.service.SysParamsService;
import com.czg.system.service.VersionService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 用户端
 * @author GYJoker
 */
@RestController
@RequestMapping("/user")
public class UserVersionController {
    @Resource
    private VersionService versionService;
    @Resource
    private SysParamsService sysParamsService;

    /**
     * 获取版本信息
     *
     * @param source 渠道
     * @param type   类型
     * @return VersionDTO
     */
    @GetMapping("/version/info/{source}/{type}")
    public CzgResult<VersionDTO> getVersionInfo(@PathVariable("source") String source, @PathVariable("type") String type) {
        return versionService.getVersionInfo(source, type);
    }


    /**
     * 帮助中心
     *
     * @return VersionDTO
     */
    @GetMapping("/getHelp")
    public CzgResult<Map<String, String>> getHelpInfo() {
        List<SysParamsDTO> systemHelps = sysParamsService.getByParamType("system_help");
        Map<String, String> systemHelpMap = systemHelps.stream().collect(Collectors.toMap(SysParamsDTO::getParamCode, SysParamsDTO::getParamValue));
        return CzgResult.success(systemHelpMap);
    }
}
