package cn.reghao.tnb.file.app.service;

import cn.reghao.oss.api.dto.ServerInfo;
import cn.reghao.oss.api.dto.rest.UploadFileRet;
import cn.reghao.oss.api.dto.rest.UploadPrepare;
import cn.reghao.oss.api.dto.rest.UploadPrepareRet;
import cn.reghao.oss.api.dto.rest.UploadSample;
import cn.reghao.tnb.file.app.rpc.OssClientManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class OssUploadService {
    private final int ossType = 1;
    private final OssClientManager ossClientManager;

    public OssUploadService(OssClientManager ossClientManager) {
        this.ossClientManager = ossClientManager;
    }

    public ServerInfo getUploadStore(int channelCode) {
        try {
            return ossClientManager.getOssClient().getServerInfo(channelCode);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public UploadPrepareRet prepareUpload(UploadPrepare uploadPrepare) {
        try {
            return ossClientManager.getOssClient().prepareUpload(uploadPrepare);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public UploadFileRet checkSample(UploadSample uploadSample) {
        try {
            return ossClientManager.getOssClient().checkSample(uploadSample);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
