package com.jwipc.sys.logic.impl;

import com.google.common.collect.Lists;
import com.jwipc.api.constant.RestCode;
import com.jwipc.api.dto.ApiResult;
import com.jwipc.sys.convert.FileApiConvert;
import com.jwipc.sys.dto.FileResposeDTO;
import com.jwipc.sys.logic.FileApiLogic;
import com.jwipc.sys.logic.FileLogic;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author shenyang.ou
 * @date 2025/3/3 19:43
 * @desc
 */
@Service
@RequiredArgsConstructor
public class FileApiLogicImpl implements FileApiLogic {
    private final FileLogic fileLogic;
    private final FileApiConvert fileApiConvert;
    @Override
    public ApiResult uploadFile(MultipartFile file) {
        FileResposeDTO fileResposeDTO = fileLogic.uploadFile(file);
        return ApiResult.builder().code(RestCode.SAP_SUCCESS.getCode()).message("文件上传成功").data(fileResposeDTO).build();
    }

    @Override
    public ApiResult uploadFiles(MultipartFile[] files) {
        List<FileResposeDTO> result = Lists.newArrayList();
        for (MultipartFile file : files) {
            result.add(fileLogic.uploadFile(file));
        }
        return ApiResult.builder().code(RestCode.SAP_SUCCESS.getCode()).message("文件上传成功").data(result).build();
    }
}
