
package com.tmerclub.cloud.platform.controller.app;

import com.tmerclub.cloud.common.constant.ConfigNameConstant;
import com.tmerclub.cloud.common.constant.Constant;
import com.tmerclub.cloud.common.i18n.I18nMessage;
import com.tmerclub.cloud.common.i18n.LanguageEnum;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.platform.service.SysConfigService;
import io.swagger.v3.oas.annotations.Operation;
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.RestController;

import java.util.Objects;

/**
 * @Author lth
 * @Date 2021/6/1 13:59
 */
@RestController("appSysConfigController")
@RequestMapping("/ua/app/sys_config")
@Tag(name = "app-系统配置信息")
public class SysConfigController {

    @Autowired
    private SysConfigService sysConfigService;

    @GetMapping("/service_protocol")
    @Operation(summary = "获取服务条款", description = "获取服务条款")
    public ServerResponseEntity<String> getServiceProtocol() {
        Integer dbLang = I18nMessage.getLang();
        if (Objects.equals(LanguageEnum.LANGUAGE_ZH_CN.getLang(), dbLang)) {
            return ServerResponseEntity.success(sysConfigService.getValue(ConfigNameConstant.SERVICE_PROTOCOL_CN));
        } else {
            return ServerResponseEntity.success(sysConfigService.getValue(ConfigNameConstant.SERVICE_PROTOCOL_EN));
        }
    }

    @GetMapping("/privacy_protocol")
    @Operation(summary = "获取隐私策略", description = "获取隐私策略")
    public ServerResponseEntity<String> getPrivacyProtocol() {
        Integer dbLang = I18nMessage.getLang();
        if (Objects.equals(LanguageEnum.LANGUAGE_ZH_CN.getLang(), dbLang)) {
            return ServerResponseEntity.success(sysConfigService.getValue(ConfigNameConstant.PRIVACY_PROTOCOL_CN));
        } else {
            return ServerResponseEntity.success(sysConfigService.getValue(ConfigNameConstant.PRIVACY_PROTOCOL_EN));
        }
    }

    @GetMapping("/pay_settlement_type")
    @Operation(summary = "获取支付系统配置", description = "获取支付系统配置")
    public ServerResponseEntity<String> getPaySettlementType() {
        return ServerResponseEntity.success(sysConfigService.getValue(Constant.PAY_SETTLEMENT_CONFIG));
    }
}
