package ink.wgink.module.file.service.v2.impl;

import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.module.file.enums.UploadTypeEnum;
import ink.wgink.module.file.pojo.dtos.FileUploadSuccessDTO;
import ink.wgink.module.file.service.IFileService;
import ink.wgink.module.file.service.v2.IFileV2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @ClassName: FileV2ServiceImpl
 * @Description: 文件V2
 * @Author: wanggeng
 * @Date: 2022/4/13 16:15
 * @Version: 1.0
 */
@Service
public class FileV2ServiceImpl extends DefaultBaseService implements IFileV2Service {

    @Autowired
    private IFileService fileService;

    @Override
    public FileUploadSuccessDTO uploadSingle(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> requestParams) {
        fileService.uploadSingle(uploadFile, uploadTypeEnum, requestParams);
        FileUploadSuccessDTO fileUploadSuccessDTO = new FileUploadSuccessDTO();
        fileUploadSuccessDTO.setFileId(requestParams.get("fileId").toString());
        fileUploadSuccessDTO.setFileName(requestParams.get("fileName").toString());
        fileUploadSuccessDTO.setFileSize(Long.valueOf(requestParams.get("fileSize").toString()));
        return fileUploadSuccessDTO;
    }

    @Override
    public FileUploadSuccessDTO uploadSingleByToken(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> requestParams) {
        fileService.uploadSingle(token, uploadFile, uploadTypeEnum, requestParams);
        FileUploadSuccessDTO fileUploadSuccessDTO = new FileUploadSuccessDTO();
        fileUploadSuccessDTO.setFileId(requestParams.get("fileId").toString());
        fileUploadSuccessDTO.setFileName(requestParams.get("fileName").toString());
        fileUploadSuccessDTO.setFileSize(Long.valueOf(requestParams.get("fileSize").toString()));
        return fileUploadSuccessDTO;
    }

    @Override
    public FileUploadSuccessDTO uploadSingleByUserId(String userId, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> requestParams) {
        fileService.uploadSingleByUserId(userId, uploadFile, uploadTypeEnum, requestParams);
        FileUploadSuccessDTO fileUploadSuccessDTO = new FileUploadSuccessDTO();
        fileUploadSuccessDTO.setFileId(requestParams.get("fileId").toString());
        fileUploadSuccessDTO.setFileName(requestParams.get("fileName").toString());
        fileUploadSuccessDTO.setFileSize(Long.valueOf(requestParams.get("fileSize").toString()));
        return fileUploadSuccessDTO;
    }


}
