
package com.tmerclub.cloud.multishop.controller.multishop;

import com.tmerclub.cloud.api.platform.feign.ConfigFeignClient;
import com.tmerclub.cloud.common.constant.ConfigNameConstant;
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.multishop.dto.ShopUserRegisterDTO;
import com.tmerclub.cloud.multishop.service.ShopUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * @author lth
 */
@RestController("multishopShopUserRegisterController")
@RequestMapping("/ua/shopUserRegister")
@Tag(name = "multishop-商家注册")
public class ShopUserRegisterController {

    @Autowired
    private ShopUserService shopUserService;

    @DubboReference
    private ConfigFeignClient configFeignClient;

    @Operation(summary = "注册")
    @PostMapping
    public ServerResponseEntity<Void> register(@Valid @RequestBody ShopUserRegisterDTO shopUserRegisterDTO) {
        // 创建并保存用户信息
        shopUserService.register(shopUserRegisterDTO);
        return ServerResponseEntity.success();
    }

    @Operation(summary = "获取商家注册协议")
    @GetMapping("/get_merchant_register_protocol")
    public ServerResponseEntity<String> getMerchantRegisterProtocol() {
        Integer dbLang = I18nMessage.getLang();
        if (Objects.equals(LanguageEnum.LANGUAGE_ZH_CN.getLang(), dbLang)) {
            return configFeignClient.getConfig(ConfigNameConstant.MERCHANT_REGISTER_PROTOCOL_CN);
        } else {
            return configFeignClient.getConfig(ConfigNameConstant.MERCHANT_REGISTER_PROTOCOL_EN);
        }
    }

    @Operation(summary = "获取开店协议")
    @GetMapping("/get_shop_protocol")
    public ServerResponseEntity<String> getShopProtocol() {
        Integer dbLang = I18nMessage.getLang();
        if (Objects.equals(LanguageEnum.LANGUAGE_ZH_CN.getLang(), dbLang)) {
            return configFeignClient.getConfig(ConfigNameConstant.SHOP_PROTOCOL_CN);
        } else {
            return configFeignClient.getConfig(ConfigNameConstant.SHOP_PROTOCOL_EN);
        }
    }

}
