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

import cn.reghao.jutil.jdk.result.WebResult;
import cn.reghao.oss.api.iface.ConsoleService;
import cn.reghao.oss.console.account.service.UserContext;
import cn.reghao.oss.api.dto.ServerInfo;
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.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author reghao
 * @date 2024-02-27 09:12:14
 */
@Api(tags = "存储对象页面")
@Controller
@RequestMapping("/store/object")
public class StoreObjectPageController {
    private final ConsoleService consoleService;

    public StoreObjectPageController(ConsoleService consoleService) {
        this.consoleService = consoleService;
    }

    @ApiOperation(value = "文件列表页面")
    @GetMapping(value = "/list")
    public String index(@RequestParam(value = "env", required = false) String env,
                        @RequestParam(value = "type", required = false) String type,
                        @RequestParam(value = "appName", required = false) String appName, Model model) throws Exception {
        if (env == null) {
            env = "test";
        }

        if (type == null) {
            type = "test";
        }

        /*PageRequest pageRequest = PageSort.pageRequest();
        Page<DiskFile> page = Page.empty();*/

        model.addAttribute("env", env);
        model.addAttribute("type", type);
        /*model.addAttribute("page", page);
        model.addAttribute("list", page.getContent());*/
        return "/object/index";
    }

    @ApiOperation(value = "文件上传页面")
    @GetMapping(value = "/upload")
    public String uploadPage(Model model) {
        int loginUser = UserContext.getUserId();
        int channelId = 105;
        try {
            ServerInfo serverInfo = consoleService.getUploadStore(loginUser, channelId);
            model.addAttribute("serverInfo", serverInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "/object/upload";
    }

    @ApiOperation(value = "文件上传接口")
    @PostMapping(value = "/upload")
    @ResponseBody
    public String uploadFile(MultipartFile[] files) {
        return WebResult.success();
    }
}
