
package com.tmerclub.cloud.platform.controller;

import com.alibaba.fastjson2.JSON;
import com.tmerclub.cloud.common.response.ResponseEnum;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.platform.constant.WebConfigType;
import com.tmerclub.cloud.platform.service.SysConfigService;
import com.tmerclub.cloud.platform.vo.WebConfigVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 网站配置信息表
 *
 * @author Orange
 */
@RestController("allWebConfigController")
@RequestMapping("/ua/web_config")
@Tag(name = "网站配置信息表")
public class WebConfigController {

    @Autowired
    private SysConfigService sysConfigService;

    @GetMapping("/get_activity")
    @Operation(summary = "获取当前激活的网站配置", description = "获取当前激活的网站配置")
    @Parameter(name = "webConfigType", description = "配置类型")
    public ServerResponseEntity<WebConfigVO> getActivityWebConfig(@RequestParam("webConfigType") String webConfigType) {
        WebConfigType paramKey = WebConfigType.instance(webConfigType);
        if (Objects.isNull(paramKey)) {
            return ServerResponseEntity.fail(ResponseEnum.HTTP_MESSAGE_NOT_READABLE);
        }
        String paramValue = sysConfigService.getValue(paramKey.value());
        WebConfigVO webConfigVO = JSON.parseObject(paramValue, WebConfigVO.class);
        webConfigVO.setParamKey(webConfigType);
        return ServerResponseEntity.success(webConfigVO);
    }
}
