
package com.tmerclub.cloud.supplier.controller.supplier;

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.supplier.dto.SupplierUserRegisterDTO;
import com.tmerclub.cloud.supplier.service.SupplierUserService;
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("supplierSupplierUserRegisterController")
@RequestMapping("/ua/supplier_user_register")
@Tag(name = "supplier-供应商账户注册")
public class SupplierUserRegisterController {

    @Autowired
    private SupplierUserService supplierUserService;

    @DubboReference
    private ConfigFeignClient configFeignClient;


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

    @Operation(summary = "获取供应商注册协议")
    @GetMapping("/get_supplier_register_protocol")
    public ServerResponseEntity<String> getSupplierRegisterProtocol() {
        Integer dbLang = I18nMessage.getLang();
        if (Objects.equals(LanguageEnum.LANGUAGE_ZH_CN.getLang(), dbLang)) {
            return configFeignClient.getConfig(ConfigNameConstant.SUPPLIER_REGISTER_PROTOCOL_CN);
        } else {
            return configFeignClient.getConfig(ConfigNameConstant.SUPPLIER_REGISTER_PROTOCOL_EN);
        }
    }

    @Operation(summary = "获取供应商合作协议")
    @GetMapping("/get_supplier_protocol")
    public ServerResponseEntity<String> getSupplierProtocol() {
        Integer dbLang = I18nMessage.getLang();
        if (Objects.equals(LanguageEnum.LANGUAGE_ZH_CN.getLang(), dbLang)) {
            return configFeignClient.getConfig(ConfigNameConstant.SUPPLIER_SHOP_PROTOCOL_CN);
        } else {
            return configFeignClient.getConfig(ConfigNameConstant.SUPPLIER_SHOP_PROTOCOL_EN);
        }
    }

}
