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

import cn.reghao.jutil.jdk.result.Result;
import cn.reghao.jutil.jdk.result.WebResult;
import cn.reghao.oss.console.app.model.dto.ChannelProcessDto;
import cn.reghao.oss.console.app.model.dto.ChannelScopeDto;
import cn.reghao.oss.console.app.model.dto.UploadChannelDto;
import cn.reghao.oss.console.app.service.UploadChannelService;
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 15:05:30
 */
@Slf4j
@Api(tags = "上传通道接口")
@RestController
@RequestMapping("/api/store/channel")
public class UploadChannelController {
    private final UploadChannelService uploadChannelService;

    public UploadChannelController(UploadChannelService uploadChannelService) {
        this.uploadChannelService = uploadChannelService;
    }

    @ApiOperation(value = "添加上传通道")
    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
    public String addUploadChannel(@Validated UploadChannelDto uploadChannelDto) {
        Result result = uploadChannelService.add(uploadChannelDto);
        return WebResult.result(result);
    }

    @ApiOperation(value = "修改通道可见范围")
    @PostMapping(value = "/update/scope", produces = MediaType.APPLICATION_JSON_VALUE)
    public String updateChannelScope(@Validated ChannelScopeDto channelScopeDto) {
        uploadChannelService.updateScope(channelScopeDto);
        return WebResult.success();
    }

    @ApiOperation(value = "修改通道是否返回 url")
    @PostMapping(value = "/update/seturl", produces = MediaType.APPLICATION_JSON_VALUE)
    public String updateChannelProcess(@Validated ChannelProcessDto channelProcessDto) {
        uploadChannelService.updateSeturl(channelProcessDto);
        return WebResult.success();
    }
}
