var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { lamports, toBigNumber } from '../../types';
import { AssetNotFoundError } from '../../errors';
const DEFAULT_BASE_URL = 'https://mockstorage.example.com/';
const DEFAULT_COST_PER_BYTE = 1;
export class MockStorageDriver {
    constructor(options) {
        var _a;
        this.cache = {};
        this.baseUrl = (_a = options === null || options === void 0 ? void 0 : options.baseUrl) !== null && _a !== void 0 ? _a : DEFAULT_BASE_URL;
        this.costPerByte = toBigNumber((options === null || options === void 0 ? void 0 : options.costPerByte) != null
            ? options === null || options === void 0 ? void 0 : options.costPerByte
            : DEFAULT_COST_PER_BYTE);
    }
    getUploadPrice(bytes) {
        return __awaiter(this, void 0, void 0, function* () {
            return lamports(this.costPerByte.muln(bytes));
        });
    }
    upload(file) {
        return __awaiter(this, void 0, void 0, function* () {
            const uri = `${this.baseUrl}${file.uniqueName}`;
            this.cache[uri] = file;
            return uri;
        });
    }
    download(uri) {
        return __awaiter(this, void 0, void 0, function* () {
            const file = this.cache[uri];
            if (!file) {
                throw new AssetNotFoundError(uri);
            }
            return file;
        });
    }
}
//# sourceMappingURL=MockStorageDriver.js.map