package com.lij.himeeter.web.controller.system;

import com.lij.himeeter.common.core.controller.BaseController;
import com.lij.himeeter.common.core.domain.AjaxResult;
import com.lij.himeeter.common.core.domain.model.RegisterBody;
import com.lij.himeeter.common.utils.StringUtils;
import com.lij.himeeter.framework.web.service.SysRegisterService;
import com.lij.himeeter.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <pre>
 *
 * 文件名 :  SysRegisterCtrl
 * 创建时间 : 2025年01月06日 04:52
 *
 * 文件描述 : 注册验证
 *
 * </pre>
 *
 * @author Nobita
 * @version 1.0.0
 */

@RestController
public class SysRegisterCtrl extends BaseController {

    @Autowired
    private SysRegisterService registerService;

    @Autowired
    private ISysConfigService configService;

    @PostMapping("/register")
    public AjaxResult register(@RequestBody RegisterBody user) {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
            return error("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(user);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }
}
