package ink.wgink.module.file.controller.app.api.v2;

import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.file.enums.UploadTypeEnum;
import ink.wgink.module.file.pojo.dtos.v2.FileUploadSuccessDTO;
import ink.wgink.module.file.service.v2.IFileService;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResultData;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: FileAppController
 * @Description: APP文件上传
 * @Author: WangGeng
 * @Date: 2019-08-02 15:38
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "文件管理接口")
@RestController("fileAppControllerV2")
@RequestMapping(ISystemConstant.APP_PREFIX + "/file/v2")
public class FileAppController extends DefaultBaseController {

    @Autowired
    private IFileService fileV2Service;

    @ApiOperation(value = "上传文件", notes = "上传文件接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "file", value = "文件name", paramType = "query")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("upload-file")
    public SuccessResultData<FileUploadSuccessDTO> uploadFile(@RequestHeader("token") String token, @RequestParam("file") MultipartFile file) {
        return new SuccessResultData<>(fileV2Service.uploadSingleByToken(token, file, UploadTypeEnum.FILE));
    }

    @ApiOperation(value = "上传文件", notes = "上传文件接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "userId", paramType = "header"),
            @ApiImplicitParam(name = "file", value = "文件name", paramType = "query")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("upload-file-release")
    public SuccessResultData<FileUploadSuccessDTO> uploadFileByUserId(@RequestHeader("userId") String userId, @RequestParam("file") MultipartFile file) {
        return new SuccessResultData<>(fileV2Service.uploadSingleByUserId(userId, file, UploadTypeEnum.FILE));
    }

    @ApiOperation(value = "上传图片", notes = "上传图片接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "image", value = "文件name", paramType = "query")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("upload-image")
    public SuccessResultData<FileUploadSuccessDTO> uploadImage(@RequestHeader("token") String token, @RequestParam("image") MultipartFile image) {
        return new SuccessResultData<>(fileV2Service.uploadSingleByToken(token, image, UploadTypeEnum.IMAGE));
    }

    @ApiOperation(value = "上传图片", notes = "上传图片接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "userId", paramType = "header"),
            @ApiImplicitParam(name = "image", value = "文件name", paramType = "query")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("upload-image-release")
    public SuccessResultData<FileUploadSuccessDTO> uploadImageByUserId(@RequestHeader("userId") String userId, @RequestParam("image") MultipartFile image) {
        return new SuccessResultData<>(fileV2Service.uploadSingleByUserId(userId, image, UploadTypeEnum.IMAGE));
    }

    @ApiOperation(value = "上传视频", notes = "上传视频接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "video", value = "文件video", paramType = "query")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("upload-video")
    public SuccessResultData<FileUploadSuccessDTO> uploadVideo(@RequestHeader("token") String token, @RequestParam("video") MultipartFile video) {
        return new SuccessResultData<>(fileV2Service.uploadSingleByToken(token, video, UploadTypeEnum.VIDEO));
    }

    @ApiOperation(value = "上传视频", notes = "上传视频接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "userId", paramType = "header"),
            @ApiImplicitParam(name = "video", value = "文件video", paramType = "query")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("upload-video-release")
    public SuccessResultData<FileUploadSuccessDTO> uploadVideoByUserId(@RequestHeader("userId") String userId, @RequestParam("video") MultipartFile video) {
        return new SuccessResultData<>(fileV2Service.uploadSingleByUserId(userId, video, UploadTypeEnum.VIDEO));
    }

    @ApiOperation(value = "上传音频", notes = "上传音频接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", paramType = "header"),
            @ApiImplicitParam(name = "audio", value = "文件audio", paramType = "query")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("upload-audio")
    public SuccessResultData<FileUploadSuccessDTO> uploadAudio(@RequestHeader("token") String token, @RequestParam("audio") MultipartFile audio) {
        return new SuccessResultData<>(fileV2Service.uploadSingleByToken(token, audio, UploadTypeEnum.AUDIO));
    }

    @ApiOperation(value = "上传音频", notes = "上传音频接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "userId", paramType = "header"),
            @ApiImplicitParam(name = "audio", value = "文件audio", paramType = "query")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("upload-audio-release")
    public SuccessResultData<FileUploadSuccessDTO> uploadAudioByUserId(@RequestHeader("userId") String userId, @RequestParam("audio") MultipartFile audio) {
        return new SuccessResultData<>(fileV2Service.uploadSingleByUserId(userId, audio, UploadTypeEnum.AUDIO));
    }

}
