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

import cn.reghao.jutil.jdk.result.Result;
import cn.reghao.oss.web.app.model.dto.StoreNodeUpdateDto;
import cn.reghao.jutil.jdk.result.WebResult;
import cn.reghao.oss.web.app.model.po.StoreNode;
import cn.reghao.oss.web.app.service.StoreNodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author reghao
 * @date 2024-02-23 11:29:14
 */
@Slf4j
@Api(tags = "存储节点数据接口")
@RestController
@RequestMapping("/api/oss/store/node")
public class StoreNodeController {
    private final StoreNodeService storeNodeService;

    public StoreNodeController(StoreNodeService storeNodeService) {
        this.storeNodeService = storeNodeService;
    }

    @ApiOperation(value = "添加存储节点")
    @PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public String addStoreNode(@RequestBody @Validated StoreNode storeNode) {
        storeNodeService.add(storeNode);
        return WebResult.success();
    }

    @ApiOperation(value = "设置存储节点的域名")
    @PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
    public String updateStoreNodeDomain(@Validated StoreNodeUpdateDto storeNodeUpdateDto) {
        Result result = storeNodeService.updateDomain(storeNodeUpdateDto);
        return WebResult.result(result);
    }

    @ApiOperation(value = "删除存储节点")
    @DeleteMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String deleteStoreNode(@PathVariable("id") Integer nodeId) {
        Result result = storeNodeService.delete(nodeId);
        return WebResult.result(result);
    }

    @ApiOperation(value = "设置存储节点状态")
    @PostMapping(value = "/status/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String setStatus(@PathVariable("id") Integer nodeId) {
        return WebResult.success();
    }
}
