package com.bcrjl.miwifi.controller;

import com.bcrjl.miwifi.common.response.R;
import com.bcrjl.miwifi.common.util.MiWifiUtil;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.Objects;

/**
 * API接口
 *
 * @author yanqs
 */
@AllArgsConstructor
@RestController
@RequestMapping("/api/system/")
public class SystemController {

    private final MiWifiUtil miWifiUtil;

    /**
     * 路由器状态
     *
     * @return 路由器状态
     */
    @GetMapping("/status")
    public R status() {
        return R.data(miWifiUtil.getStatus());
    }

    /**
     * 获取网关前缀
     *
     * @return 网关前缀字符串
     */
    @GetMapping("/gateway-prefix")
    public R getGatewayPrefix() {
        return R.data(miWifiUtil.getGatewayPrefix());
    }


    /**
     * 测试是否连通
     *
     * @return
     */
    @GetMapping("/test")
    public R test() {
        Map<String, Object> loginInfo = miWifiUtil.getLoginInfo();
        if (Objects.isNull(loginInfo)) {
            return R.fail("无法链接路由器信息");
        }
        return R.success("连接路由器成功");
    }
}
