package com.cnooc.expert.controller.file;

import com.cnooc.expert.common.response.ApiResult;
import com.cnooc.expert.controller.common.AbstractBaseController;
import com.cnooc.expert.controller.file.model.request.DownloadInfoReq;
import com.cnooc.expert.external.file.model.response.DownLoadInfoApiResp;
import com.cnooc.expert.service.file.FileMockService;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@AllArgsConstructor
@RestController
@RequestMapping("/mock/file")
public class FileMockController extends AbstractBaseController {

    private final FileMockService fileMockService;

    @PostMapping("/put/object")
    public ApiResult<List<DownLoadInfoApiResp>> filePutObject(@RequestParam("file") MultipartFile file,
                                                              @RequestParam("fileType") Integer fileType) throws IOException {
        List<DownLoadInfoApiResp> apiResp = fileMockService.putObject(file, fileType);
        return ApiResult.successWithResult(apiResp);
    }


    @PostMapping("/generatorDownloadInfo")
    public ApiResult<List<DownLoadInfoApiResp>> downloadInfo(@RequestBody @Validated DownloadInfoReq req) {
        List<DownLoadInfoApiResp> apiResp = fileMockService.downloadInfo(req.getPathId());
        return ApiResult.successWithResult(apiResp);
    }

}
