import { QiniuNetworkError, QiniuRequestError } from '../errors';
export var errorMap = {
    networkError: new QiniuNetworkError('mock', 'message'),
    invalidParams: new QiniuRequestError(400, 'mock', 'message'),
    expiredToken: new QiniuRequestError(401, 'mock', 'message'),
    gatewayUnavailable: new QiniuRequestError(502, 'mock', 'message'),
    serviceUnavailable: new QiniuRequestError(503, 'mock', 'message'),
    serviceTimeout: new QiniuRequestError(504, 'mock', 'message'),
    serviceError: new QiniuRequestError(599, 'mock', 'message'),
    invalidUploadId: new QiniuRequestError(612, 'mock', 'message') // 无效的 upload id
};
var MockApi = /** @class */ (function () {
    function MockApi() {
        this.interceptorMap = new Map();
        this.direct = this.direct.bind(this);
        this.getUpHosts = this.getUpHosts.bind(this);
        this.uploadChunk = this.uploadChunk.bind(this);
        this.uploadComplete = this.uploadComplete.bind(this);
        this.initUploadParts = this.initUploadParts.bind(this);
        this.deleteUploadedChunks = this.deleteUploadedChunks.bind(this);
    }
    MockApi.prototype.clearInterceptor = function () {
        this.interceptorMap.clear();
    };
    MockApi.prototype.setInterceptor = function (name, interceptor) {
        this.interceptorMap.set(name, interceptor);
    };
    MockApi.prototype.callInterceptor = function (name, defaultValue) {
        var interceptor = this.interceptorMap.get(name);
        if (interceptor != null) {
            return interceptor();
        }
        return defaultValue;
    };
    MockApi.prototype.direct = function () {
        var defaultData = Promise.resolve({
            reqId: 'req-id',
            data: {
                fsize: 270316,
                bucket: 'test2222222222',
                hash: 'Fs_k3kh7tT5RaFXVx3z1sfCyoa2Y',
                name: '84575bc9e34412d47cf3367b46b23bc7e394912a',
                key: '84575bc9e34412d47cf3367b46b23bc7e394912a.html'
            }
        });
        return this.callInterceptor('direct', defaultData);
    };
    MockApi.prototype.getUpHosts = function () {
        var defaultData = Promise.resolve({
            reqId: 'req-id',
            data: {
                ttl: 86400,
                io: { src: { main: ['iovip-z2.qbox.me'] } },
                up: {
                    acc: {
                        main: ['upload-z2.qiniup.com'],
                        backup: ['upload-dg.qiniup.com', 'upload-fs.qiniup.com']
                    },
                    old_acc: { main: ['upload-z2.qbox.me'], info: 'compatible to non-SNI device' },
                    old_src: { main: ['up-z2.qbox.me'], info: 'compatible to non-SNI device' },
                    src: { main: ['up-z2.qiniup.com'], backup: ['up-dg.qiniup.com', 'up-fs.qiniup.com'] }
                },
                uc: { acc: { main: ['uc.qbox.me'] } },
                rs: { acc: { main: ['rs-z2.qbox.me'] } },
                rsf: { acc: { main: ['rsf-z2.qbox.me'] } },
                api: { acc: { main: ['api-z2.qiniu.com'] } }
            }
        });
        return this.callInterceptor('getUpHosts', defaultData);
    };
    MockApi.prototype.uploadChunk = function () {
        var defaultData = Promise.resolve({
            reqId: 'req-id',
            data: {
                etag: 'FuYYVJ1gmVCoGk5C5r5ftrLXxE6m',
                md5: '491309eddd8e7233e14eaa25216594b4'
            }
        });
        return this.callInterceptor('uploadChunk', defaultData);
    };
    MockApi.prototype.uploadComplete = function () {
        var defaultData = Promise.resolve({
            reqId: 'req-id',
            data: {
                key: 'test.zip',
                hash: 'lsril688bAmXn7kiiOe9fL4mpc39',
                fsize: 11009649,
                bucket: 'test',
                name: 'test'
            }
        });
        return this.callInterceptor('uploadComplete', defaultData);
    };
    MockApi.prototype.initUploadParts = function () {
        var defaultData = Promise.resolve({
            reqId: 'req-id',
            data: { uploadId: '60878b9408bc044043f5d74f', expireAt: 1620100628 }
        });
        return this.callInterceptor('initUploadParts', defaultData);
    };
    MockApi.prototype.deleteUploadedChunks = function () {
        var defaultData = Promise.resolve({
            reqId: 'req-id',
            data: undefined
        });
        return this.callInterceptor('deleteUploadedChunks', defaultData);
    };
    return MockApi;
}());
export { MockApi };
//# sourceMappingURL=index.mock.js.map