package com.railway.web.controller.system;

import com.railway.common.core.controller.BaseController;
import com.railway.common.core.domain.AjaxResult;
import com.railway.common.core.domain.model.RegisterBody;
import com.railway.framework.web.service.SysRegisterService;
import com.railway.system.service.ISysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 注册验证
 *
 * @author railway
 */
@Api(tags = "权限认证 - 用户注册")
@RestController
public class SysRegisterController extends BaseController {

  private final SysRegisterService registerService;
  private final ISysConfigService configService;

  public SysRegisterController(SysRegisterService registerService,
      ISysConfigService configService) {
    this.registerService = registerService;
    this.configService = configService;
  }

  @ApiOperation(value = "注册", notes = "注册方法", response = AjaxResult.class)
  @PostMapping("/register")
  public AjaxResult register(@RequestBody RegisterBody user) {
    if (!configService.selectRegisterUser()) {
      return error("当前系统没有开启注册功能！");
    }
    String msg = registerService.register(user);
    return StringUtils.isEmpty(msg) ? success() : error(msg);
  }
}
