package cn.reghao.oss.console.app.controller.page;

import cn.reghao.oss.console.app.model.po.StoreNode;
import cn.reghao.oss.console.app.model.vo.KeyValue;
import cn.reghao.oss.console.app.service.StoreNodeService;
import cn.reghao.oss.console.app.service.UserNodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author reghao
 * @date 2019-08-30 18:49:15
 */
@Api(tags = "我的节点页面")
@Controller
@RequestMapping("/store/my")
public class UserNodePageController {
    private final UserNodeService userNodeService;
    private final StoreNodeService storeNodeService;

    public UserNodePageController(UserNodeService userNodeService, StoreNodeService storeNodeService) {
        this.userNodeService = userNodeService;
        this.storeNodeService = storeNodeService;
    }

    @ApiOperation(value = "我的节点列表页面")
    @GetMapping(value = "/list")
    public String userNodesPage(@RequestParam(value = "env", required = false) String env,
                              @RequestParam(value = "appType", required = false) String appType,
                              Model model) {
        List<StoreNode> list = userNodeService.getUserStoreNodes();
        model.addAttribute("env", env);
        model.addAttribute("type", appType);
        model.addAttribute("list", list);
        return "/usernode/index1";
    }

    @ApiOperation(value = "我的节点创建页面")
    @GetMapping(value = "/add")
    public String addNodePage(Model model) {
        List<KeyValue> storeNodes = storeNodeService.getNodeKeyValues();
        model.addAttribute("storeNodes", storeNodes);
        return "/usernode/add";
    }

    @ApiOperation(value = "节点详情页面")
    @GetMapping(value = "/detail/{appId}")
    public String nodeDetailPage(@PathVariable(value = "appId") String appId, Model model) {
        model.addAttribute("list", Collections.emptyList());
        return "/usernode/detail";
    }
}
