package cn.reghao.devops.mgr.aliyun.controller;

import cn.reghao.devops.mgr.app.model.vo.AppConfigVO;
import cn.reghao.devops.mgr.util.DefaultSetting;
import cn.reghao.devops.mgr.util.PageSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author reghao
 * @date 2025-03-28 09:30:20
 */
@Api(tags = "阿里云管理页面")
@Controller
@RequestMapping("/aliyun")
public class AliyunController {
    @ApiOperation(value = "阿里云 key 页面", notes = "N")
    @GetMapping("/key")
    public String aliyunKeyPage(@RequestParam(value = "env", required = false) String env,
                                Model model) {
        if (env == null) {
            env = DefaultSetting.getDefaultEnv();
        }

        PageRequest pageRequest = PageSort.pageRequest();
        Page<AppConfigVO> page = Page.empty();

        model.addAttribute("env", env);
        model.addAttribute("page", page);
        model.addAttribute("list", page.getContent());
        return "/devops/aliyun/keylist";
    }

    @ApiOperation(value = "证书列表页面", notes = "N")
    @GetMapping("/cert")
    public String certPage(@RequestParam(value = "env", required = false) String env,
                                Model model) {
        if (env == null) {
            env = DefaultSetting.getDefaultEnv();
        }

        PageRequest pageRequest = PageSort.pageRequest();
        Page<AppConfigVO> page = Page.empty();

        model.addAttribute("env", env);
        model.addAttribute("page", page);
        model.addAttribute("list", page.getContent());
        return "/devops/aliyun/certlist";
    }
}
